import 'package:aitrainer_app/bloc/menu/menu_bloc.dart'; import 'package:aitrainer_app/localization/app_localization.dart'; import 'package:aitrainer_app/widgets/bottom_nav.dart'; import 'package:aitrainer_app/widgets/menu_page_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; // ignore: must_be_immutable class MenuPage extends StatelessWidget { static const routeName = '/menu_page'; int parent; MenuBloc menuBloc; MenuPage({this.parent}); @override Widget build(BuildContext context) { menuBloc = BlocProvider.of(context); return Scaffold( appBar: AppBar( backgroundColor: Colors.transparent, title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(AppLocalizations.of(context).translate("Tests")), Image.asset( 'asset/image/WT_long_logo.png', fit: BoxFit.cover, height: 65.0, ), ], ), leading: IconButton( icon: Icon(Icons.arrow_back, color: Colors.white), onPressed: () => { menuBloc.add(MenuTreeUp(parent: 0)) }, ), ), body: Container( decoration: BoxDecoration( image: DecorationImage( image: AssetImage('asset/image/WT_menu_dark.png'), fit: BoxFit.fill, alignment: Alignment.center, ), ), child: BlocConsumer( listener: (context, state) { if (state is MenuError) { Scaffold.of(context).showSnackBar(SnackBar( backgroundColor: Colors.orange, content: Text("error", style: TextStyle(color: Colors.white)))); } else if ( state is MenuLoading ) { return MenuPageWidget(); } }, // ignore: missing_return builder: (context, state) { if ( state is MenuInitial ) { return LoadingMenuDialog(); } else if (state is MenuReady ) { return MenuPageWidget(); } else if ( state is MenuLoading ) { return LoadingMenuDialog(); } } ) ), bottomNavigationBar: BottomNavigator(bottomNavIndex: 0) ); } } class LoadingMenuDialog extends StatefulWidget { LoadingMenuDialog({Key key}) : super(key: key); @override State createState() => _LoadingMenuDialog(); } class _LoadingMenuDialog extends State { @override void initState() { super.initState(); /// We require the initializers to run after the loading screen is rendered SchedulerBinding.instance.addPostFrameCallback((_) { BlocProvider.of(context).add(MenuCreate()); }); } @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async => false, child: Center( child: Card( child: Container( width: 80, height: 80, padding: EdgeInsets.all(12.0), child: CircularProgressIndicator(), color: Colors.transparent, ), ), ), ); } }