converted into non go router
parent
c088dbc2a2
commit
226899893f
|
@ -33,13 +33,13 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
|||
UserData? userData = await AuthService.instance
|
||||
.webLogin(username: event.username, password: event.password);
|
||||
_userData = userData;
|
||||
emit(UserLoggedIn(userData: userData));
|
||||
emit(UserLoggedIn(userData: _userData));
|
||||
} catch (e) {
|
||||
emit(UserError(message: e.toString()));
|
||||
}
|
||||
});
|
||||
on<LoadLoggedInUser>((event, emit) {
|
||||
emit(UserLoggedIn(userData: event.userData));
|
||||
emit(UserLoggedIn(userData: _userData));
|
||||
});
|
||||
on<GetUuid>((event, emit) async {
|
||||
ScanResult result = await QRCodeBarCodeScanner.instance.scanner();
|
||||
|
|
|
@ -18,11 +18,10 @@ class UserLogin extends UserEvent{
|
|||
}
|
||||
|
||||
class LoadLoggedInUser extends UserEvent {
|
||||
final UserData? userData;
|
||||
LoadLoggedInUser({this.userData});
|
||||
// final UserData? userData;
|
||||
LoadLoggedInUser();
|
||||
}
|
||||
|
||||
class GetUuid extends UserEvent {
|
||||
|
||||
GetUuid();
|
||||
}
|
||||
|
|
|
@ -4,13 +4,14 @@ import 'package:device_preview/device_preview.dart';
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:unit2/bloc/bloc/user_bloc.dart';
|
||||
import 'package:unit2/utils/app_router.dart';
|
||||
import 'package:unit2/utils/global_context.dart';
|
||||
import 'package:unit2/utils/global_context.dart';
|
||||
import './utils/router.dart';
|
||||
import './utils/global.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
// void main() => runApp(
|
||||
|
@ -21,12 +22,12 @@ void main() {
|
|||
// );
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
AppRouter? _appRouter;
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
BuildContext? parentContext = NavigationService.navigatorKey.currentContext;
|
||||
_appRouter = AppRouter();
|
||||
final mediaQueryData =
|
||||
MediaQueryData.fromWindow(WidgetsBinding.instance.window);
|
||||
screenWidth = mediaQueryData.size.width;
|
||||
|
@ -43,16 +44,16 @@ class MyApp extends StatelessWidget {
|
|||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (parentContext) => UserBloc(),
|
||||
create: (_) => UserBloc(),
|
||||
),
|
||||
],
|
||||
child: MaterialApp.router(
|
||||
key: NavigationService.navigatorKey,
|
||||
child: MaterialApp(
|
||||
navigatorKey: NavigationService.navigatorKey,
|
||||
// useInheritedMediaQuery: true,
|
||||
// locale: DevicePreview.locale(context),
|
||||
// builder: DevicePreview.appBuilder,
|
||||
routeInformationParser: goRouter.routeInformationParser,
|
||||
routerDelegate: goRouter.routerDelegate,
|
||||
// routeInformationParser: goRouter.routeInformationParser,
|
||||
// routerDelegate: goRouter.routerDelegate,
|
||||
// routeInformationProvider: goRouter.routeInformationProvider,
|
||||
title: 'uniT2 - Universal Tracker and Tracer',
|
||||
theme: ThemeData(
|
||||
|
@ -64,6 +65,7 @@ class MyApp extends StatelessWidget {
|
|||
fontFamily: 'LexendDeca',
|
||||
),
|
||||
debugShowCheckedModeBanner: false,
|
||||
onGenerateRoute: _appRouter!.onGenerateRoute,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,9 @@ class _DrawerScreenState extends State<DrawerScreen> {
|
|||
if (state is UserLoggedIn) {
|
||||
return ZoomDrawer(
|
||||
controller: zoomDrawerController,
|
||||
menuScreen: MenuScreen(userData: state.userData,),
|
||||
menuScreen: MenuScreen(
|
||||
userData: state.userData,
|
||||
),
|
||||
mainScreen: SizedBox(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: const MainScreen()),
|
||||
|
@ -39,7 +41,6 @@ class _DrawerScreenState extends State<DrawerScreen> {
|
|||
);
|
||||
}
|
||||
return const UniTSplashScreen();
|
||||
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class _UniT2LoginState extends State<UniT2Login> {
|
|||
print("login" + state.toString());
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
context.goNamed('home', extra: state.userData);
|
||||
Navigator.pushReplacementNamed(context, '/module-screen');
|
||||
}
|
||||
if (state is UuidLoaded) {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) {
|
||||
|
|
|
@ -1,14 +1,32 @@
|
|||
// import 'package:flutter/cupertino.dart';
|
||||
// import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:unit2/bloc/bloc/user_bloc.dart';
|
||||
import 'package:unit2/screens/unit2/login/login.dart';
|
||||
import 'package:unit2/utils/global_context.dart';
|
||||
|
||||
// class AppRouter{
|
||||
// Route onGenerateRoute(RouteSettings routeSettings){
|
||||
// switch(routeSettings.name){
|
||||
// case '/':
|
||||
// return BlocProvider(
|
||||
// create: (context) => UserBloc()..add(GetApkVersion()),
|
||||
// child: const UniT2Login(),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
import '../screens/unit2/homepage.dart/components/drawer-screen.dart';
|
||||
|
||||
class AppRouter {
|
||||
Route onGenerateRoute(RouteSettings routeSettings) {
|
||||
switch (routeSettings.name) {
|
||||
case '/':
|
||||
BlocProvider.of<UserBloc>(
|
||||
NavigationService.navigatorKey.currentContext!)
|
||||
.add(GetApkVersion());
|
||||
return MaterialPageRoute(builder: (_) {
|
||||
return const UniT2Login();
|
||||
});
|
||||
case '/module-screen':
|
||||
BlocProvider.of<UserBloc>( NavigationService.navigatorKey.currentContext!).add(LoadLoggedInUser());
|
||||
return MaterialPageRoute(builder: (_) {
|
||||
return const DrawerScreen();
|
||||
});
|
||||
|
||||
default:
|
||||
return MaterialPageRoute(builder: (context) {
|
||||
return Container();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,78 +1,78 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:unit2/bloc/bloc/user_bloc.dart';
|
||||
import 'package:unit2/model/login_data/user_info/user_data.dart';
|
||||
import 'package:unit2/screens/unit2/login/qr_login.dart';
|
||||
import 'package:unit2/screens/unit2/roles/qr_code_scanner.dart/scan.dart';
|
||||
import 'package:unit2/screens/unit2/roles/qr_code_scanner.dart/settings_screen.dart';
|
||||
import 'package:unit2/screens/unit2/signature/signature_pad.dart';
|
||||
import 'package:unit2/utils/global_context.dart';
|
||||
import 'package:unit2/utils/scanner.dart';
|
||||
import '../screens/docsms/components/doc_info_tile.dart';
|
||||
import '../screens/docsms/request_receipt.dart';
|
||||
import '../screens/sos/add_mobile.dart';
|
||||
import '../screens/sos/request_sos.dart';
|
||||
import '../screens/unit2/login/login.dart';
|
||||
import '../screens/unit2/homepage.dart/components/drawer-screen.dart';
|
||||
import '../screens/unit2/profile/profile.dart';
|
||||
import '../screens/unit2/roles/registration_in_charge/home.dart';
|
||||
// import 'package:flutter/cupertino.dart';
|
||||
// import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
// import 'package:go_router/go_router.dart';
|
||||
// import 'package:unit2/bloc/bloc/user_bloc.dart';
|
||||
// import 'package:unit2/model/login_data/user_info/user_data.dart';
|
||||
// import 'package:unit2/screens/unit2/login/qr_login.dart';
|
||||
// import 'package:unit2/screens/unit2/roles/qr_code_scanner.dart/scan.dart';
|
||||
// import 'package:unit2/screens/unit2/roles/qr_code_scanner.dart/settings_screen.dart';
|
||||
// import 'package:unit2/screens/unit2/signature/signature_pad.dart';
|
||||
// import 'package:unit2/utils/global_context.dart';
|
||||
// import 'package:unit2/utils/scanner.dart';
|
||||
// import '../screens/docsms/components/doc_info_tile.dart';
|
||||
// import '../screens/docsms/request_receipt.dart';
|
||||
// import '../screens/sos/add_mobile.dart';
|
||||
// import '../screens/sos/request_sos.dart';
|
||||
// import '../screens/unit2/login/login.dart';
|
||||
// import '../screens/unit2/homepage.dart/components/drawer-screen.dart';
|
||||
// import '../screens/unit2/profile/profile.dart';
|
||||
// import '../screens/unit2/roles/registration_in_charge/home.dart';
|
||||
|
||||
final GoRouter goRouter = GoRouter(routes: <GoRoute>[
|
||||
GoRoute(
|
||||
path: '/',
|
||||
name: 'login',
|
||||
builder: (context, state) {
|
||||
return BlocProvider(
|
||||
create: (context) => UserBloc()..add(GetApkVersion()),
|
||||
child: const UniT2Login(),
|
||||
);
|
||||
},
|
||||
routes: [
|
||||
// final GoRouter goRouter = GoRouter(routes: <GoRoute>[
|
||||
// GoRoute(
|
||||
// name: 'qr-login',
|
||||
// path: 'qr-login',
|
||||
// builder: ((context, state) => const QRLogin())),
|
||||
GoRoute(
|
||||
name: 'home',
|
||||
path: 'home',
|
||||
builder: (context, state) {
|
||||
UserData userData = state.extra as UserData;
|
||||
return BlocProvider<UserBloc>.value(
|
||||
value: UserBloc()..add((LoadLoggedInUser(userData: userData))),
|
||||
child: const DrawerScreen(),
|
||||
);
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
name: 'profile',
|
||||
path: 'profile',
|
||||
builder: (context, state) {
|
||||
UserData userData = state.extra as UserData;
|
||||
return BlocProvider<UserBloc>.value(
|
||||
value: UserBloc()
|
||||
..add((LoadLoggedInUser(userData: userData))),
|
||||
child: const Profile(),
|
||||
);
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
name: 'signature',
|
||||
path: 'signature',
|
||||
builder: (context, state) => const SignaturePad(),
|
||||
)
|
||||
])
|
||||
]),
|
||||
GoRoute(
|
||||
name: 'add-mobile',
|
||||
path: 'add-moble',
|
||||
builder: (context, state) => AddMobile(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
name: 'request-sos',
|
||||
path: 'request-sos',
|
||||
builder: (context, state) => const RequestSOS(),
|
||||
)
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
// path: '/',
|
||||
// name: 'login',
|
||||
// builder: (context, state) {
|
||||
// return BlocProvider(
|
||||
// create: (context) => UserBloc()..add(GetApkVersion()),
|
||||
// child: const UniT2Login(),
|
||||
// );
|
||||
// },
|
||||
// routes: [
|
||||
// // GoRoute(
|
||||
// // name: 'qr-login',
|
||||
// // path: 'qr-login',
|
||||
// // builder: ((context, state) => const QRLogin())),
|
||||
// GoRoute(
|
||||
// name: 'home',
|
||||
// path: 'home',
|
||||
// builder: (context, state) {
|
||||
// UserData userData = state.extra as UserData;
|
||||
// return BlocProvider<UserBloc>.value(
|
||||
// value: UserBloc()..add((LoadLoggedInUser(userData: userData))),
|
||||
// child: const DrawerScreen(),
|
||||
// );
|
||||
// },
|
||||
// routes: [
|
||||
// GoRoute(
|
||||
// name: 'profile',
|
||||
// path: 'profile',
|
||||
// builder: (context, state) {
|
||||
// UserData userData = state.extra as UserData;
|
||||
// return BlocProvider<UserBloc>.value(
|
||||
// value: UserBloc()
|
||||
// ..add((LoadLoggedInUser(userData: userData))),
|
||||
// child: const Profile(),
|
||||
// );
|
||||
// },
|
||||
// routes: [
|
||||
// GoRoute(
|
||||
// name: 'signature',
|
||||
// path: 'signature',
|
||||
// builder: (context, state) => const SignaturePad(),
|
||||
// )
|
||||
// ])
|
||||
// ]),
|
||||
// GoRoute(
|
||||
// name: 'add-mobile',
|
||||
// path: 'add-moble',
|
||||
// builder: (context, state) => AddMobile(),
|
||||
// routes: [
|
||||
// GoRoute(
|
||||
// name: 'request-sos',
|
||||
// path: 'request-sos',
|
||||
// builder: (context, state) => const RequestSOS(),
|
||||
// )
|
||||
// ]),
|
||||
// ]),
|
||||
// ]);
|
||||
|
|
Loading…
Reference in New Issue