问题描述
我在 lib 目录中有仪表板屏幕。 register_customer.dart 文件位于 lib 文件夹中的 customers 子目录下。我在仪表板屏幕中导入了 register_customer.dart。但是,register_customer.dart 中的 RegisterCustomer 类没有解析。这是我的代码:
lib/dashboard.dart
import 'package:Flutter/material.dart';
import './customers/register_customer.dart';
class MyDashboard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: defaultBackgroundColor,elevation: 0,leading: IconButton(
icon: Icon(
Icons.arrow_back,color: btnTextColor,),onpressed: () {
//navigate to the prevIoUs page
Navigator.pop(context);
},//navabar title text text
title: Text('Dashboard'),body: Center(
child: Column(
children: <Widget>[
Container(
margin: const EdgeInsets.all(20.0),//color: Colors.Amber[600],width: 200.0,height: 250.0,child: ListView(
children: <Widget>[
GestureDetector(
child: ListTile(
title: Text(
'Register Customer',style:
TextStyle(fontSize: 20,color: Color(0xffE06C19)),leading: Icon(
Icons.user,color: Colors.Amber,onTap: () {
**//this is where the error is being raised**
Navigator.push(
context,MaterialPageRoute(
builder: (context) => RegisterCustomer()));
},],))),);
}
}
lib/customers/register_customer.dart
import 'package:Flutter/material.dart';
class RegisterCustomer extends StatefulWidget {
@override
_RegisterCustomerState createState() => _RegisterCustomerState();
}
String _first_name;
String _last_name;
class _RegisterCustomerState extends State<RegisterCustomer> {
final GlobalKey<FormState> _formkey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Colors.purple[800],accentColor: Colors.Amber,accentColorBrightness: Brightness.dark),home: Scaffold(
appBar: AppBar(
title: Text(
'Register Customer',style: TextStyle(fontSize: 20),textAlign: TextAlign.center,body: Container(
margin: EdgeInsets.all(12),child: Form(
key: _formkey,child: Column(
mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
SizedBox(
height: 50,RaisedButton(
color: Color(0xff980CF0),textColor: Colors.white,splashColor: Colors.grey,padding: EdgeInsets.fromLTRB(10,10,10),child: Text(
'Register',style: TextStyle(
color: Colors.orangeAccent,fontSize: 17,onpressed: () {
if (!_formkey.currentState.validate()) {
return;
}
//submit data to the server
},)
],);
}
}
我在其他路线上遇到了同样的问题。我做错了什么?
解决方法
我认为导入路径不正确:
import 'package:projectname/customer/register_customer.dart
如果文件在 lib/customer/register_customer.dart