我正在使用自定义路线来创建过渡效果,但是我在使用
使用Provider
的值。
错误
Another exception was thrown: Error: Could not find the correct Provider<List<FireFavorites>> above this Favorites Widget
home.dart
return MultiProvider(
providers: [
StreamProvider.value(
value: db.streamFavorites(user.uid),
)
],
child: Scaffold(
body: StreamBuilder<NavBarItem>(
stream: _bottomNavBarBloc.itemStream,
initialData: _bottomNavBarBloc.defaultItem,
builder: (BuildContext context, AsyncSnapshot<NavBarItem> snapshot) {
switch (snapshot.data) {
case NavBarItem.SEARCH:
return Search();
case NavBarItem.BROWSE:
return Browse();
case NavBarItem.ICON:
return About();
case NavBarItem.FAVORITES:
return Favorites();
case NavBarItem.SETTINGS:
return Settings();
default:
return null;
}
},
),
bottomNavigationBar: ConvexBottomNav(navBarHandler: _navBarHandler),
),
);
}
自定义路线类别
class MyCustomPageRoute extends MaterialPageRoute {
final Widget previousPage;
MyCustomPageRoute(
{this.previousPage, WidgetBuilder builder, RouteSettings settings})
: super(builder: builder, settings: settings);
@override
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget currentPage) {
Animation<Offset> _slideAnimationPage1 =
Tween<Offset>(begin: Offset(0.0, 0.0), end: Offset(-1.0, 0.0))
.animate(animation);
Animation<Offset> _slideAnimationPage2 =
Tween<Offset>(begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0))
.animate(animation);
return Stack(
children: <Widget>[
SlideTransition(position: _slideAnimationPage1, child: previousPage),
SlideTransition(position: _slideAnimationPage2, child: currentPage),
],
);
}
}
使用Browse()
中的类似类。我只是想导航到一个文档。但是使用MyCustomPageRoute
会导致Provider
错误。
Navigator.push(
context,
MyCustomPageRoute(
previousPage: this,
builder: (context) => Document(
documentID: docid,
),
),
);
我想在main.dart中拥有收藏夹StreamProvider
,但是我无法在其中访问经过身份验证的用户的uid
,否则我不知道如何访问它。变得可用。以下是如何在Provider
中设置main.dart
。我可以在home.dart
中进行一个简单的请求,获取收藏夹并将其添加到Content()
中,并在整个应用程序中访问它们,但是我想拥有一个流。
main.dart
return MultiProvider(
providers: [
StreamProvider<FirebaseUser>.value(
value: FirebaseAuth.instance.onAuthStateChanged,
),
ChangeNotifierProvider<Content>.value(
value: Content(),
),
],
child: MaterialApp(
title: '',
theme: ThemeData(
fontFamily: 'OpenSans',
brightness: Brightness.light,
primaryColor: Color(0xff2398C3),
),
home: WelcomePage(),
),
);
任何想法如何解决?