我正在尝试将参数从slider页面传递到MovieInfo
页面:
I/flutter ( 6196): Could not find a generator for route RouteSettings("/MovieInfo", Instance of 'Arguments') in the _WidgetsAppState.
I/flutter ( 6196): Make sure your root app widget has provided a way to generate
I/flutter ( 6196): this route.
I/flutter ( 6196): Generators for routes are searched for in the following order:
I/flutter ( 6196): 1. For the "/" route, the "home" property, if non-null, is used.
I/flutter ( 6196): 2. Otherwise, the "routes" table is used, if it has an entry for the route.
字符串
我的主文件:
import 'package:flutter/material.dart';
import 'package:movie/arguments.dart';
import 'package:movie/pages/MovieInfo.dart';
import 'package:movie/pages/Serieses.dart';
import 'package:movie/pages/episodes.dart';
import 'package:movie/pages/livetv.dart';
import 'package:movie/pages/types.dart';
import 'pages/Home.dart';
import 'pages/ChooseLocation.dart';
import 'pages/loading.dart';
import 'pages/Movies.dart';
import 'pages/playvideo.dart';
void main() {
runApp(MaterialApp(
initialRoute: '/Movies',
onGenerateRoute: (settings) {
if (settings.name == '/videoPlay') {
final args = settings.arguments as Arguments;
return MaterialPageRoute(
builder: (context) =>
VideoPlayerApp(url: args.url, dataSource: args.dataSource),
);
} else if (settings.name == '/episodes') {
final args = settings.arguments as Arguments;
return MaterialPageRoute(
builder: (context) =>
episodes(SeriesName: args.name, SeriesPath: args.path),
);
} else if (settings.name == '/MovieInfo') {
final args = settings.arguments as Arguments;
return MaterialPageRoute(
builder: (context) => MovieInfo(name: args.name, path: args.path));
}
return null;
},
routes: {
'/': (context) => Loading(),
'/location': (context) => ChoosLocation(),
'/home': (context) => Home(),
'/Movies': (context) => Movies(),
'/Series': (context) => Series(),
'/liveTv': (context) => liveTv(),
'/Types': (context) => Types()
},
));
}
型
我的MovieInfo
屏幕:
import 'package:flutter/material.dart';
import 'dart:ui';
class MovieInfo extends StatelessWidget {
late String name;
late String path;
MovieInfo({required this.name, required this.path});
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight: 300,
flexibleSpace: FlexibleSpaceBar(
background: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 6.0, sigmaY: 6.0),
child: ImageFiltered(
imageFilter: ImageFilter.blur(sigmaX: 6.0, sigmaY: 6.0),
child: Image(
image: NetworkImage(path),
width: double.maxFinite,
fit: BoxFit.cover,
),
)),
),
),
SliverToBoxAdapter(
child: Column(
children: [
Container(
margin: EdgeInsets.only(right: 760),
child: ElevatedButton(
onPressed: () {},
child: Text('watch'),
),
),
Container(
child: Text(
"In the application main() method, call SystemChrome. setPreferredOrientations() with the list of preferred orientations that your app supports. To lock the device to a single orientation, you can pass a list with a single item. For a list of all the possible values, check out DeviceOrientation ."),
)
],
),
)
],
),
);
}
}
型
这是我做了一列Carnival滑块的地方:
child: Row(
children: [
Container(
width: 200,
height: double.maxFinite,
color: Color.fromRGBO(0, 0, 0, 0.5),
child: Column(children: [
SizedBox(height: 10),
ListTile(
onTap: () {
_scrollToPosition(200);
},
title: Text(
'Drama',
style: TextStyle(color: Colors.white),
),
)
]),
),
Expanded(
child: SingleChildScrollView(
controller: _scrollcontroller,
child: Column(
children: [
SizedBox(
height: 100,
),
CSlider(
list: movies,
name: 'Top movies',
),
CSlider(
list: movies,
name: 'Horror',
),
CSlider(
list: movies,
name: 'Drama',
),
CSlider(
list: movies,
name: 'Kids',
),
CSlider(
list: movies,
name: 'Shows',
)
],
),
),
)
],
),
型
我检查了很多次,但没有结果!我不知道哪里发生了异常。
3条答案
按热度按时间jhkqcmku1#
从错误消息和您提供的代码来看,问题似乎在于您如何在
MaterialApp
小部件中设置路由生成。1.路由生成重叠:
你同时使用了
onGenerateRoute
和routes
。为了清晰起见,最好还是使用一个。我建议使用onGenerateRoute
,因为你要传递参数。2.未定义路由:
目前,如果
onGenerateRoute
中的条件都不匹配,则返回null
。相反,请考虑返回默认路由或错误页面。3.参数类型:
确保在导航到
/MovieInfo
时,传递的是正确的Arguments
类型。以下是修改后的
onGenerateRoute
:字符串
4.导航提示:
导航时,请确保您正在使用:
型
最后,仔细检查代码中涉及导航的其他部分,以确保它们设置正确。
bpsygsoo2#
如果你必须同时使用
routes
和onGenerateRoute
,那也没关系,关键是要确保它们能和谐地工作。1.无参数路由处理:
对于不需要参数的路由,继续使用
routes
属性。2.处理带参数的路由:
对于需要参数的路由,请使用
onGenerateRoute
属性。确保正确处理路由生成,特别是对于/MovieInfo
路由。3.未定义路由:
当
onGenerateRoute
中的条件都不匹配时,您将返回null
。这可能会导致您看到的错误。相反,请考虑通过重定向到默认路由或显示错误页面来处理此情况。下面是一个稍微调整的
onGenerateRoute
:字符串
4.导航:
导航到需要参数的路由时,请使用:用途:
型
通过这种结构,您可以允许
routes
和onGenerateRoute
共存,onGenerateRoute
处理需要参数的路由,routes
处理其余路由。yws3nbqq3#
更新:
导致错误的是
OrientationBuilder
,所以我通过删除OrientationBuilder
解决了这个问题。