gpt4 book ai didi

android - 切换到新页面时使用抽屉时出现 flutter 错误

转载 作者:行者123 更新时间:2023-12-03 04:35:52 25 4
gpt4 key购买 nike

我试图通过做一个应用程序来学习 flutter ,一切都很好,但是现在我在通过抽屉传递新页面时遇到了一个错误,老实说,idk为什么但当我实现良好的页面更改页面开始代码时到代码下面的设置页面


//flutter build apk --split-per-abi
passToHomePage(BuildContext context) {
Navigator.push(context, MaterialPageRoute(builder: (context) => HomePage()));
}

passToSettingsPage(BuildContext context) {
Navigator.push(
context, MaterialPageRoute(builder: (context) => SettingsStateful()));
}

Drawer drawerReturner(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
Container(
height: 100,
child: DrawerHeader(
decoration: BoxDecoration(
color: Colors.green,
),
child: Text(
'Menù',
style: TextStyle(
color: Colors.white,
fontSize: 24,
),
),
),
),
ListTile(
leading: Icon(Icons.add),
title: Text('"Add" button :D'),
onTap: passToSettingsPage(context),
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings (WIP)'),
onTap: passToSettingsPage(context),
)
],
),
);
}

void main() {
runApp(MainApp());
}

class MainApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Random app',
theme: ThemeData(
primarySwatch: Colors.green,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: HomePage(),
);
}
}

class HomePage extends StatefulWidget {
HomePage({this.title = "Home page"});

final String title;
@override
HomePageState createState() => HomePageState();
}

class HomePageState extends State<HomePage> {
int counter = 0;

void incrementCounter() {
setState(() {
counter++;
});
}

void decrementCounter() {
setState(() {
if (counter > -1) {
counter--;
}
});
}

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (counter > -1)
Text('Hai cliccato il bottone $counter volte')
else
Text('Non puoi far arrivare il bottone a meno di 0!'),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FloatingActionButton(
onPressed: incrementCounter,
tooltip: 'Increment',
heroTag: null,
child: Icon(Icons.add)),
Divider(
indent: 75,
),
FloatingActionButton(
onPressed: decrementCounter,
tooltip: 'Decrement',
heroTag: null,
child: Icon(Icons.remove)),
],
),
],
)),
drawer: drawerReturner(context),
);
}
}

class SettingsStateful extends StatefulWidget {
SettingsStateful({this.title = "Settings"});

final String title;
@override
SettingsPage createState() => SettingsPage();
}

class SettingsPage extends State<SettingsStateful> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: new Center(
child: Column(children: <Widget>[Text("Hewwo")]),
),
drawer: drawerReturner(context),
);
}
}
这是 flutter 的医生:
[√] Flutter (Channel stable, 1.20.4, on Microsoft Windows [Versione 10.0.19041.508], locale it-IT)
• Flutter version 1.20.4 at C:\flutter
• Framework revision fba99f6cf9 (2 weeks ago), 2020-09-14 15:32:52 -0700
• Engine revision d1bc06f032
• Dart version 2.9.2


[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\giuse\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: D:\Softwares\Android studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.

[!] Android Studio (version 4.0)
• Android Studio at D:\Softwares\Android studio
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (1 available)
• sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)

! Doctor found issues in 1 category.
和idk为什么会出现错误,但不再显示错误,但是这里出现了“主要”错误 Failed assertion: line 4016 pos 12: '!_debugLocked': is not true.

最佳答案

首先弹出,然后推送到新屏幕。

Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
Container(
height: 100,
child: DrawerHeader(
decoration: BoxDecoration(
color: Colors.green,
),
child: Text(
'Menù',
style: TextStyle(
color: Colors.white,
fontSize: 24,
),
),
),
),
ListTile(
leading: Icon(Icons.add),
title: Text('"Add" button :D'),
onTap: (){
Navigator.pop(context);
passToSettingsPage(context);
}
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings (WIP)'),
onTap: (){
Navigator.pop(context);
passToSettingsPage(context);
}
)
],
),
);

关于android - 切换到新页面时使用抽屉时出现 flutter 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64139747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com