Flutter 为什么我的Flitter应用程序在转到特定页面时会冻结?
因此,我在几个小时不工作的情况下加载了我的颤振项目,当我试图点击一个按钮,该按钮应该让我进入一个特定的页面时,整个应用程序都冻结了。上次我运行它时,它运行得很好,我没有改变任何东西。我重新启动了程序,我的电脑和它仍然冻结。所有其他根到页面的按钮都可以工作,所以我认为这是该页面代码的问题。这是该页面的完整代码:Flutter 为什么我的Flitter应用程序在转到特定页面时会冻结?,flutter,dart,freeze,Flutter,Dart,Freeze,因此,我在几个小时不工作的情况下加载了我的颤振项目,当我试图点击一个按钮,该按钮应该让我进入一个特定的页面时,整个应用程序都冻结了。上次我运行它时,它运行得很好,我没有改变任何东西。我重新启动了程序,我的电脑和它仍然冻结。所有其他根到页面的按钮都可以工作,所以我认为这是该页面代码的问题。这是该页面的完整代码: import 'package:flutter/material.dart'; import 'package:workwise2/classes/taskClass.dart'; im
import 'package:flutter/material.dart';
import 'package:workwise2/classes/taskClass.dart';
import 'package:workwise2/config.dart';
class TodoTasks extends StatefulWidget {
@override
_TodoTasksState createState() => _TodoTasksState();
}
class _TodoTasksState extends State<TodoTasks> {
Settings settings = Settings();
BottomNavBarConfig bottomNavBarConfig = BottomNavBarConfig();
List <Task> tasks = [
Task(title: "Maths HW", description: "Complete Q2, Q6 and Q7 with GPCs on Q8", subject: "maths", day: 12, month: 4, year: 2021),
Task(title: "English test", description: "Revise quotes for anger", subject: "english", day: 13, month: 4, year: 2021),
];
@override
Widget build(BuildContext context) {
int _currentIndex = 0;
String _requestedPage;
return Scaffold(
appBar: AppBar(
title: Text(
"Tasks",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30.0
),
),
backgroundColor: Colors.indigoAccent[700],
leading: Icon(Icons.check_box_rounded, size: 40.0,),
),
body: AnimatedContainer(
duration: Duration(milliseconds: 1700),
child: ListView.builder(
itemBuilder: (context, index) {
Color _checkButtonColour;
double _checkButtonElevation;
IconData _bookmark = Icons.bookmark_border;
if (tasks[index].state == "todo") {
_checkButtonColour = Colors.red[600];
_checkButtonElevation = 0.0;
}
else if (tasks[index].state == "doing") {
_checkButtonColour = Colors.amber;
_checkButtonElevation = 5.0;
}
else if (tasks[index].state == "done") {
_checkButtonColour = Colors.green;
_checkButtonElevation = 10.0;
}
while (tasks[index].favourited == true) {
_bookmark = Icons.bookmark;
}
while (tasks[index].favourited == false) {
_bookmark = Icons.bookmark_border;
}
return Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 3.0),
child: Card(
elevation: 10.0,
child: ListTile(
contentPadding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 5.0),
onTap: () {},
leading: IconButton(
onPressed: () {
tasks[index].favourited = !tasks[index].favourited;
print(tasks[index].favourited);
},
icon: Icon(_bookmark),
iconSize: 35.0,
color: settings.subjectColours[tasks[index].subject]
),
title: Text(tasks[index].title, maxLines: 1, overflow: TextOverflow.fade,),
subtitle: Text(tasks[index].description, maxLines: 1, overflow: TextOverflow.ellipsis,),
trailing: AnimatedContainer(
height: 80.0,
width: 100.0,
duration: Duration(milliseconds: 1700),
child: Row(
children: <Widget> [
SizedBox(
width: 40.0,
height: 40.0,
child: MaterialButton(
elevation: _checkButtonElevation,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6.0)),
onPressed: () {
if (tasks[index].state == "todo") {
setState(() {
tasks[index].state = "doing";
});
} else if (tasks[index].state == "doing") {
setState(() {
tasks[index].state = "done";
});
} else if (tasks[index].state == "done") {
setState(() {
tasks[index].state = "todo";
});
}
},
padding: EdgeInsets.all(2.0),
color: _checkButtonColour,
),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.more_vert),
)
],
),
),
),
),
);
},
itemCount: tasks.length,
)
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
backgroundColor: Colors.indigoAccent[700],
fixedColor: Colors.white,
unselectedFontSize: bottomNavBarConfig.unactiveTextSize,
unselectedIconTheme: IconThemeData(
size: bottomNavBarConfig.unactiveIconSize
),
selectedFontSize: bottomNavBarConfig.activeTextSize,
selectedIconTheme: IconThemeData(
size: bottomNavBarConfig.activeIconSize
),
type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.check_box_rounded),
label: "Tasks"
),
BottomNavigationBarItem(
icon: Icon(Icons.lightbulb),
label: "Learn"
),
BottomNavigationBarItem(
icon: Icon(Icons.home_rounded),
label: "Home"
),
BottomNavigationBarItem(
icon: Icon(Icons.library_books_rounded),
label: "Notes"
),
],
onTap: (index) {
if (index == 0) {
_requestedPage = "/todotasks";
}
else if (index == 2) {
_requestedPage = "/home";
}
else if (index == 3) {
_requestedPage = "/notes";
}
else if (index == 1) {
_requestedPage = "/sets";
}
setState(() {
_currentIndex = index;
});
Navigator.popAndPushNamed(context, _requestedPage);
},
)
);
}
}
导入“包装:颤振/材料.省道”;
导入“package:workwise2/classes/taskClass.dart”;
导入“package:workwise2/config.dart”;
类ToToTasks扩展StatefulWidget{
@凌驾
_TodoTasksState createState()=>\u TodoTasksState();
}
类_ToToTaskState扩展了状态{
设置=设置();
BottomNavBarConfig BottomNavBarConfig=BottomNavBarConfig();
列出任务=[
任务(标题:“数学HW”,描述:“完成第二季度、第六季度和第七季度,第八季度GPC”,主题:“数学”,日:12,月:4,年:2021),
任务(标题:“英语测试”,描述:“修改愤怒的引语”,主题:“英语”,日期:13,月份:4,年份:2021),
];
@凌驾
小部件构建(构建上下文){
int _currentIndex=0;
字符串_requestedPage;
返回脚手架(
appBar:appBar(
标题:正文(
“任务”,
样式:TextStyle(
fontWeight:fontWeight.bold,
字体大小:30.0
),
),
背景颜色:颜色。靛蓝色[700],
前导:图标(图标。复选框四舍五入,大小:40.0,),
),
主体:动画容器(
持续时间:持续时间(毫秒:1700),
子项:ListView.builder(
itemBuilder:(上下文,索引){
颜色_checkbuttoncolor;
双方格按钮高度;
IconData\u bookmark=图标。书签\u边框;
如果(任务[索引].state==“todo”){
_checkButtonColour=颜色。红色[600];
_checkButtonElevation=0.0;
}
else if(任务[索引].state==“正在进行”){
_checkButtonColour=Colors.琥珀色;
_checkButtonElevation=5.0;
}
else if(任务[索引].state==“完成”){
_checkButtonColour=Colors.green;
_checkButtonElevation=10.0;
}
while(tasks[index].favorited==true){
_书签=图标。书签;
}
while(任务[index].favorited==false){
_书签=图标。书签\u边框;
}
返回填充(
填充:边缘组。对称(水平:8.0,垂直:3.0),
孩子:卡片(
标高:10.0,
孩子:ListTile(
内容填充:边集。对称(垂直:10.0,水平:5.0),
onTap:(){},
领先:IconButton(
已按下:(){
任务[index]。收藏夹=!任务[index]。收藏夹;
打印(任务[索引]);
},
图标:图标(_书签),
iconSize:35.0,
颜色:设置。主题颜色[任务[索引]。主题]
),
标题:文本(任务[索引]。标题,最大行数:1,溢出:TextOverflow.fade,),
字幕:文本(任务[索引]。说明,最大行数:1,溢出:TextOverflow。省略号,),
尾随:动画容器(
身高:80.0,
宽度:100.0,
持续时间:持续时间(毫秒:1700),
孩子:排(
儿童:[
大小盒子(
宽度:40.0,
身高:40.0,
子项:材质按钮(
标高:_检查按钮标高,
形状:RoundedRectangleBorder(borderRadius:borderRadius.circular(6.0)),
已按下:(){
如果(任务[索引].state==“todo”){
设置状态(){
任务[索引]。状态=“正在进行”;
});
}else if(任务[索引].state==“正在进行”){
设置状态(){
任务[index].state=“完成”;
});
}else if(任务[索引].state==“完成”){
设置状态(){
任务[索引].state=“todo”;
});
}
},
填充:所有边缘设置(2.0),
颜色:_CheckButton颜色,
),
),
图标按钮(
按下:(){},
图标:图标(更多图标),
)
],
),
),
),
),
);
},
itemCount:tasks.length,
)
),
底部导航栏:底部导航栏(
currentIndex:_currentIndex,
背景颜色:颜色。靛蓝色[700],
固定颜色:颜色。白色,
未选择的FontSize:bottomNavBarConfig.unactiveTextSize,
未选择的主题:IconThemeData(
大小:bottomNavBarConfig.unActiviecOnSize
),
selectedFontSize:bottomNavBarConfig.activeTextSize,
选择主题:图标主题数据(
大小:bottomNavBarConfig.activeIconSize
),
类型:BottomNavigationBarType.fixed,
项目:[
底部
Navigator.of(context).pushNamedUntil(_requestedPage);