在加载应用程序时,每当我尝试点击下面代码中创建的按钮时,调试控制台就会给出这个错误。
手势RouteSettings捕捉到的════════异常无法在_WidgetsAppState中找到路由═══════════════════════════════════════════的生成器(“/1000hz_route”,null)。
下面是我试图运行的代码。我将如何修复这个错误?
import 'package:flutter/material.dart';
import 'package:audiotest/UI/player_widget.dart';
import 'package:flutter/material.dart';
import 'package:audiotest/UI/homepage1.dart';
const flutaud1 =
'https://audio.jukehost.co.uk/694139d474ee606401cc3aa8160159ac14662cd8/093232dd0c4';
void main() => runApp(new MaterialApp(
title: "TestAudio",
initialRoute: '/audio_selection',
routes: {
'/audio_selection': (context) => AudioSelection(),
'/1000hz_route': (context) => MainPersistentTabBar1(),
}));
class AudioSelection extends StatefulWidget {
@override
IntroScreenstate2 createState() => IntroScreenstate2();
}
class IntroScreenstate2 extends State<AudioSelection> {
Widget _tab(List<Widget> children) {
return Center(
child: new Container(
child: new SingleChildScrollView(
padding: EdgeInsets.all(16.0),
child: Column(
children: children
.map((w) => Container(child: w, padding: EdgeInsets.all(6.0)))
.toList(),
),
),
));
}
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: _tab([
Text(
'Audio 1000 HZ',
style: TextStyle(fontWeight: FontWeight.bold),
),
PlayerWidget(url: flutaud1),
new MaterialButton(
child: new Text('Select 1000 hz'),
onPressed: () {
Navigator.pushNamed(context, '/1000hz_route');
},
),
])
)
);
}
}发布于 2020-05-26 05:52:30
我不确定,但我告诉你的方式会使你的项目启动和运行。如果对你有用的话请告诉我。
在您的onPressed中执行此操作
Navigator.push(context, new MaterialPageRoute(
builder: (context) => MainPersistentTabBar1())
);而不是
Navigator.pushNamed(context, '/1000hz_route');https://stackoverflow.com/questions/62015296
复制相似问题