在我的项目中,我遇到了一个非常奇怪的错误。在项目中,它们是一个名为Dashboard.dart的Dart文件,在android studio中按下运行后,在android studio的控制台屏幕中可以看到dashboard.dart文件中的全部代码。
并且也在projectfile> android中自动生成一个文件,该文件的名称为仪表板的状态类.dart代码(文件名:_DashboardPageState)也为空。
我试图删除该文件,但是再次运行该代码,该文件会自动再次生成。
在dashboard.dart文件中,我还尝试完全更改代码,或者如果我完全删除该文件,仍然显示相同的错误。
为了更好地理解,我还上传了错误,一些重要的代码以及生成文件的屏幕截图。
main.dart
import 'package:flutter/material.dart';
import 'package:udharibook/Screens/SplashScreen.dart';
void main(){
runApp(
MaterialApp(
title: 'Udhari Book',
home:SplashScreen(),
debugShowCheckedModeBanner: false,
theme: ThemeData(
backgroundColor: Color.fromRGBO(242, 242, 242, 1.0)
),
)
);
}
仪表板Page.dart
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:udharibook/Screens/CustomerDetails.dart';
import 'package:udharibook/Screens/UserProfile.dart';
import 'package:udharibook/services/authservice.dart';
import 'Customer_Support.dart';
class DashboardPage extends StatefulWidget {
final String userName;
String imgUrl =
'https://firebasestorage.googleapis.com/v0/b/udhari-book.appspot.com/o/DefaultImage.png?alt=media&token=06bddd3e-7f11-476b-a982-dfb21096f9c7';
DashboardPage({Key key, this.userName, this.imgUrl}) : super(key: key);
@override
_DashboardPageState createState() => _DashboardPageState();
}
class _DashboardPageState extends State<DashboardPage> {
@override
void initState() {
super.initState();
// FirebaseAuth _auth = FirebaseAuth.instance;
// DatabaseReference DBRef = FirebaseDatabase.instance.reference().child('Users');
// _auth.currentUser().then((curUser){
// DBRef.child(curUser.uid).once().then((DataSnapshot user){
//userName = user.value['Name'];
setState(() {
print('The name of Username is:' + widget.imgUrl);
});
// });
//});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
widget.userName,
style: TextStyle(fontFamily: 'Exo2'),
),
backgroundColor: Color(0xFFA22A2B),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {
print("Search Clicked");
}),
IconButton(
icon: Icon(Icons.sort),
onPressed: () {
print("Sort Clicked");
}),
],
),
//Drawer Header i.e. Upper part with Image and Name
drawer: SafeArea(
child: Drawer(
child: ListView(
children: <Widget>[
Container(
padding: EdgeInsets.all(13.0),
height: 180.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/Drawer.png'),
fit: BoxFit.cover,
)),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.white,
radius: 60.0,
child: ClipOval(
child: SizedBox(
height: 110.0,
width: 110.0,
child: Image.network(
widget.imgUrl,
fit: BoxFit.cover,
)),
)),
Padding(
padding: EdgeInsets.only(top: 3.0),
),
Center(
child: Text(
widget.userName,
style: TextStyle(
color: Colors.white,
fontSize: 22.0,
fontFamily: 'Exo2'),
),
)
],
),
),
CustomMenu(
Icons.person,
'Profile',
() => {
Navigator.pop(context),
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => UserProfile(
isCancelBtnVisible: true,
)))
}),
CustomMenu(Icons.assessment, 'Reports', () => {}),
CustomMenu(Icons.settings, 'Settings', () => {}),
CustomMenu(
Icons.perm_phone_msg,
'Customer Support',
() => {
Navigator.pop(context),
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => CustSupport()))
}),
CustomMenu(
Icons.lock, 'Log Out', () => {AuthService().signOut()}),
],
),
),
),
floatingActionButton:
FloatingActionButton.extended(
icon: Icon(Icons.person_add),
label: Text('New User',
style: TextStyle(fontFamily: 'Exo2',
fontWeight: FontWeight.w600,
fontSize: 20.0)),
backgroundColor: Color.fromRGBO(162, 42, 43, 1),
foregroundColor: Color.fromRGBO(230, 220, 199, 1),
elevation: 10.0,
splashColor: Colors.redAccent,
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => custDetails()));
}));
}
}
class CustomMenu extends StatelessWidget {
IconData icon;
String text;
Function onTap;
CustomMenu(this.icon, this.text, this.onTap);
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(8.0, 0.0, 8.0, 0.0),
child: Container(
decoration: BoxDecoration(
border:
Border(bottom: BorderSide(color: Colors.grey.shade400))),
child: InkWell(
splashColor: Colors.redAccent,
onTap: onTap,
child: Container(
height: 60.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(icon),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
text,
style: TextStyle(
fontSize: 17.0, fontFamily: 'Exo2'),
)),
],
),
Icon(Icons.arrow_right),
],
),
))));
}
}
运行项目时出现控制台错误
Launching lib\main.dart on Moto G 5S Plus in debug mode...
Running Gradle task 'assembleDebug'...
E:\Annual Day\udhari_book\android>import 'package:firebase_auth/firebase_auth.dart';
E:\Annual Day\udhari_book\android>import 'package:firebase_database/firebase_database.dart';
E:\Annual Day\udhari_book\android>import 'package:flutter/cupertino.dart';
E:\Annual Day\udhari_book\android>import 'package:flutter/material.dart';
E:\Annual Day\udhari_book\android>import 'package:flutter/widgets.dart';
E:\Annual Day\udhari_book\android>import 'package:udharibook/Screens/UserProfile.dart';
E:\Annual Day\udhari_book\android>import 'package:udharibook/services/authservice.dart';
E:\Annual Day\udhari_book\android>import 'Customer_Support.dart';
E:\Annual Day\udhari_book\android>class DashboardPage extends StatefulWidget {
'import' is not recognized as an internal or external command,
operable program or batch file.
'import' is not recognized as an internal or external command,
operable program or batch file.
'import' is not recognized as an internal or external command,
operable program or batch file.
'import' is not recognized as an internal or external command,
operable program or batch file.
'import' is not recognized as an internal or external command,
operable program or batch file.
'import' is not recognized as an internal or external command,
operable program or batch file.
'import' is not recognized as an internal or external command,
operable program or batch file.
'import' is not recognized as an internal or external command,
operable program or batch file.
'class' is not recognized as an internal or external command,
operable program or batch file.
'final' is not recognized as an internal or external command,
operable program or batch file.
'String' is not recognized as an internal or external command,
operable program or batch file.
''https:' is not recognized as an internal or external command,
operable program or batch file.
'token' is not recognized as an internal or external command,
operable program or batch file.
E:\Annual Day\udhari_book\android>final String userName;
E:\Annual Day\udhari_book\android>String imgUrl =
E:\Annual Day\udhari_book\android>'https://firebasestorage.googleapis.com/v0/b/udhari-book.appspot.com/o/DefaultImage.png?alt=media & token=06bddd3e-7f11-476b-a982-dfb21096f9c7';
E:\Annual Day\udhari_book\android>DashboardPage({Key key, this.userName, this.imgUrl}) : super(key: key);
'DashboardPage' is not recognized as an internal or external command,
operable program or batch file.
'override' is not recognized as an internal or external command,
operable program or batch file.
'_DashboardPageState' is not recognized as an internal or external command,
operable program or batch file.
'}' is not recognized as an internal or external command,
operable program or batch file.
E:\Annual Day\udhari_book\android>_DashboardPageState createState() =; 1>_DashboardPageState()
E:\Annual Day\udhari_book\android>}
E:\Annual Day\udhari_book\android>class _DashboardPageState extends State 0<DashboardPage 1>{
E:\Annual Day\udhari_book\android>void initState() {
E:\Annual Day\udhari_book\android>super.initState();
The system cannot find the file specified.
'override' is not recognized as an internal or external command,
operable program or batch file.
'void' is not recognized as an internal or external command,
operable program or batch file.
'super.initState' is not recognized as an internal or external command,
operable program or batch file.
'//' is not recognized as an internal or external command,
operable program or batch file.
'//' is not recognized as an internal or external command,
operable program or batch file.
'//' is not recognized as an internal or external command,
operable program or batch file.
'//' is not recognized as an internal or external command,
operable program or batch file.
The filename, directory name, or volume label syntax is incorrect.
'setState' is not recognized as an internal or external command,
operable program or batch file.
E:\Annual Day\udhari_book\android>// FirebaseAuth _auth = FirebaseAuth.instance;
E:\Annual Day\udhari_book\android>// DatabaseReference DBRef = FirebaseDatabase.instance.reference().child('Users');
E:\Annual Day\udhari_book\android>// _auth.currentUser().then((curUser){
E:\Annual Day\udhari_book\android>// DBRef.child(curUser.uid).once().then((DataSnapshot user){
E:\Annual Day\udhari_book\android>//userName = user.value['Name'];
E:\Annual Day\udhari_book\android>setState(() {
E:\Annual Day\udhari_book\android>print('The name of Username is:' + widget.imgUrl);
Can't find file ('The
Can't find file name
Can't find file of
Can't find file Username
Can't find file is:'
Can't find file +
Can't find file widget.imgUrl);
E:\Annual Day\udhari_book\android>});
E:\Annual Day\udhari_book\android>// });
E:\Annual Day\udhari_book\android>//});
E:\Annual Day\udhari_book\android>}
E:\Annual Day\udhari_book\android>Widget build(BuildContext context) {
'})' is not recognized as an internal or external command,
operable program or batch file.
'//' is not recognized as an internal or external command,
operable program or batch file.
The filename, directory name, or volume label syntax is incorrect.
'}' is not recognized as an internal or external command,
operable program or batch file.
'override' is not recognized as an internal or external command,
operable program or batch file.
'Widget' is not recognized as an internal or external command,
operable program or batch file.
'return' is not recognized as an internal or external command,
operable program or batch file.
'appBar:' is not recognized as an internal or external command,
operable program or batch file.
E:\Annual Day\udhari_book\android>return Scaffold(
E:\Annual Day\udhari_book\android>appBar: AppBar(
E:\Annual Day\udhari_book\android>title: Text(widget.userName),
E:\Annual Day\udhari_book\android>backgroundColor: Color(0xFFA22A2B),,
E:\Annual Day\udhari_book\android>actions: 0<Widget 1>[
E:\Annual Day\udhari_book\android>IconButton(
'backgroundColor:' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the file specified.
'IconButton' is not recognized as an internal or external command,
operable program or batch file.
E:\Annual Day\udhari_book\android>icon: Icon(Icons.search),
E:\Annual Day\udhari_book\android>onPressed: () {
'icon:' is not recognized as an internal or external command,
operable program or batch file.
'onPressed:' is not recognized as an internal or external command,
operable program or batch file.
E:\Annual Day\udhari_book\android>print("Search Clicked");
Can't find file (Search Clicked);
E:\Annual Day\udhari_book\android>}),
E:\Annual Day\udhari_book\android>IconButton(
E:\Annual Day\udhari_book\android>icon: Icon(Icons.sort),
E:\Annual Day\udhari_book\android>onPressed: () {
E:\Annual Day\udhari_book\android>print("Sort Clicked");
Can't find file (Sort Clicked);
E:\Annual Day\udhari_book\android>}),
E:\Annual Day\udhari_book\android>],
E:\Annual Day\udhari_book\android>//Drawer Header i.e. Upper part with Image and Name
E:\Annual Day\udhari_book\android>drawer: Drawer(
E:\Annual Day\udhari_book\android>child: ListView(
E:\Annual Day\udhari_book\android>children: 0<Widget 1>[
'})' is not recognized as an internal or external command,
operable program or batch file.
'IconButton' is not recognized as an internal or external command,
operable program or batch file.
'icon:' is not recognized as an internal or external command,
operable program or batch file.
'onPressed:' is not recognized as an internal or external command,
operable program or batch file.
'})' is not recognized as an internal or external command,
operable program or batch file.
']' is not recognized as an internal or external command,
operable program or batch file.
The filename, directory name, or volume label syntax is incorrect.
'drawer:' is not recognized as an internal or external command,
operable program or batch file.
'child:' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the file specified.
'UserAccountsDrawerHeader' is not recognized as an internal or external command,
operable program or batch file.
'accountName:' is not recognized as an internal or external command,
operable program or batch file.
The filename, directory name, or volume label syntax is incorrect.
'fontSize:' is not recognized as an internal or external command,
operable program or batch file.
'fontFamily:' is not recognized as an internal or external command,
operable program or batch file.
'decoration:' is not recognized as an internal or external command,
operable program or batch file.
'image:' is not recognized as an internal or external command,
operable program or batch file.
E:\Annual Day\udhari_book\android>UserAccountsDrawerHeader(
E:\Annual Day\udhari_book\android>accountName: Text(widget.userName,
E:\Annual Day\udhari_book\android>style:TextStyle(
E:\Annual Day\udhari_book\android>fontSize: 20.0,
E:\Annual Day\udhari_book\android>fontFamily: 'Exo2',
E:\Annual Day\udhari_book\android>decoration: BoxDecoration(
E:\Annual Day\udhari_book\android>image: DecorationImage(image: NetworkImage(widget.imgUrl))
E:\Annual Day\udhari_book\android>Cu
'Cu' is not recognized as an internal or external command,
operable program or batch file.
Exception: Gradle task assembleDebug failed with exit code 1
如果看到错误,则表明我在dashboard.dart
文件中实现了该代码
我也尝试过Flutter clean,Flutter医生没有问题,升级flutter SDK并重新安装最新版本的Android Studio,最低SDK和目标SDK设置为21