Я реализовал Flutter Blo c Пример входа в систему точно так же, как страница руководства здесь :
далее, я добавил NavigationDrawer на свои страницы.
но я не не знаю, как перемещаться по страницам, я попытался нормально Navigator.pu sh, но не работает, и я использовал маршруты в MaterialApp, и, к сожалению, это не сработало, что way.
main.dart
void main() {
BlocSupervisor.delegate = SimpleBlocDelegate();
final userRepository = UserRepository();
runApp(
BlocProvider<AuthenticationBloc>(
create: (context) {
return AuthenticationBloc(userRepository: userRepository)
..add(AppStarted());
},
child: App(userRepository: userRepository),
),
);
}
class App extends StatelessWidget {
final UserRepository userRepository;
App({Key key, @required this.userRepository}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: BlocBuilder<AuthenticationBloc, AuthenticationState>(
builder: (context, state) {
if (state is AuthenticationAuthenticated) {
//return Counter();
//return ListPage();
return ProfilePage();
}
if (state is AuthenticationUnauthenticated) {
return LoginPage(userRepository: userRepository);
}
if (state is AuthenticationLoading) {
return LoadingIndicator();
}
return SplashPage();
},
),
initialRoute: '/',
routes: {
'/': (context) => SplashPage(),
'/counter': (context) => Counter(),
'/profile': (context) => ProfilePage(),
'/list': (context) => ListPage(),
},
);
}
}
navigation_drawer.dart
Widget build(BuildContext context) {
return Drawer(
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
Container(...),
ListTile(
title: Text('Profile'),
onTap: () {
/* TODO: check token is not null */
Navigator.pushNamed(context, '/profile');
},
),
ListTile(
title: Text('Counter'),
onTap: () {
Navigator.pushNamed(context, '/counter');
},
),
ListTile(
title: Text('My List'),
onTap: () {
Navigator.pushNamed(context, '/list');
},
),
],
),
);
}