英文:
Undefined class 'Widget'. Try changing the name to the name of an existing class, or creating a class with the name 'Widget'
问题
我已安装并开始了我的Flutter之旅,但在我的第一个项目后,所有的类和小部件都显示错误消息。起初它是正常工作的,但后来开始出现错误消息。
import 'package:flutter/material.dart';
void main() {
runApp(FirstApp());
}
class FirstApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Code The Best"),
),
body: Center(
child: Column(
children: [
TextButton(
onPressed: () {},
child: Text("Login"),
),
TextButton(
onPressed: () {},
child: Text("Register"),
)
],
),
),
),
);
}
}
我得到了一系列错误,包括以下几个:
-
未定义类 'BuildContext'。
请尝试将名称更改为现有类的名称,或创建一个名称为 'BuildContext' 的类。 -
未定义类 'Widget'。
请尝试将名称更改为现有类的名称,或创建一个名称为 'Widget' 的类。
英文:
I have installed and started my flutter journey but after my first project, all the classes and widgets are showing an error message. It was working at first but I later started getting the error message.
import 'package:flutter/material.dart';
void main() {
runApp(FirstApp());
}
class FirstApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Code The Best"),
),
body: Center(
child: Column(
children: [
TextButton(
onPressed: () {},
child: Text("Login"),
),
TextButton(
onPressed: () {},
child: Text("Register"),
)
],
),
),
),
);
}
}
And I get a number of errors including these:
- Undefined class 'BuildContext'.
Try changing the name to the name of an existing class, or creating a class with the name 'BuildContext'.
2.Undefined class 'Widget'.
Try changing the name to the name of an existing class, or creating a class with the name 'Widget'.
答案1
得分: 1
尝试移除 build 文件夹并重新构建。
你可以通过以下步骤完成:
- flutter clean
- flutter pub get
英文:
try removing build folder and re-building it again.
You can do this by,
- flutter clean
- flutter pub get
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论