嗨,我使用步进器在 flutter 中制作了一个虚拟测试应用程序,一切顺利,我尝试制作一个按钮,我确实制作了一个按钮,一切都很好,直到我遇到 Navigator.push 错误,它不会让我进入下一个屏幕
// ignore_for_file: no_logic_in_create_state, prefer_const_constructors, prefer_const_literals_to_create_immutables, use_super_parameters, prefer_const_constructors_in_immutables, library_private_types_in_public_api
import 'package:flutter/material.dart';
import 'secondScreen.dart';
void main() {
runApp(MainApp());
}
class MainApp extends StatefulWidget {
MainApp ({Key ? key}) : super(key: key);
@override
_MainAppState createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
int _currentstep = 0;
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
scaffoldBackgroundColor: Colors.grey,
appBarTheme: AppBarTheme(
color: Colors.grey[50]
)
),
home: Scaffold(
appBar: AppBar(
title: Text("Writing your first python code "),
),
body: Center(
child: Stepper(
currentStep: _currentstep,
onStepContinue: () => {
setState(() {
if(_currentstep < 100) {
_currentstep ++;
}
})
},
onStepCancel: () => {
setState(() {
if (_currentstep > 0) {
_currentstep --;
}
})
},
steps: [
Step(
title: Text('Step One'),
content: Text('Open Chrome')
),
Step(
title: Text('Step Two'),
content: Text('After you open chrome search for Vscode')
),
Step(
title: Text('Step Three'),
content: Text('Open Vscode')
),
Step(
title: Text('Step Four'),
content: Text('Click File')
),
Step(
title: Text('Step Five'),
content: Text('Press New Text File then click select a language')
),
Step(
title: Text('Step Six'),
content: Text('Select Python')
),
],
),
),
bottomNavigationBar: Padding(
padding: EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () => {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => SecondScreen()))
},
child: Text('Done'),
),
),
),
);
}
}
// ignore_for_file: library_private_types_in_public_api, prefer_const_constructors, use_key_in_widget_constructors
import 'package:flutter/material.dart';
class SecondScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Second Screen'),
),
);
}
}
错误:════════手势捕获异常═════════════════════════════ ══════ ════════
使用不包含导航器的上下文请求导航器操作。
════════════════════════════════════════ ═════════ ═══════════════════════════════
我尝试谷歌搜索答案,我尝试了各种按钮,我尝试更改第二个屏幕的文件名,但没有任何效果,我不知道发生了什么我的意思是我希望这只是小菜一碟,但不幸的是它不是'我认为 flutter 对初学者友好,我的意思是到目前为止我制作了两个应用程序,但不知道发生了什么
使用路由器包,例如 go_路由器
示例部分提供了代码示例。另一个不错的软件包是 GetX。