converted into non go router

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
rodolfobacuinjr 2023-01-23 13:46:09 +08:00
parent c088dbc2a2
commit 226899893f
7 changed files with 150 additions and 130 deletions

View File

@ -33,13 +33,13 @@ class UserBloc extends Bloc<UserEvent, UserState> {
UserData? userData = await AuthService.instance UserData? userData = await AuthService.instance
.webLogin(username: event.username, password: event.password); .webLogin(username: event.username, password: event.password);
_userData = userData; _userData = userData;
emit(UserLoggedIn(userData: userData)); emit(UserLoggedIn(userData: _userData));
} catch (e) { } catch (e) {
emit(UserError(message: e.toString())); emit(UserError(message: e.toString()));
} }
}); });
on<LoadLoggedInUser>((event, emit) { on<LoadLoggedInUser>((event, emit) {
emit(UserLoggedIn(userData: event.userData)); emit(UserLoggedIn(userData: _userData));
}); });
on<GetUuid>((event, emit) async { on<GetUuid>((event, emit) async {
ScanResult result = await QRCodeBarCodeScanner.instance.scanner(); ScanResult result = await QRCodeBarCodeScanner.instance.scanner();

View File

@ -18,11 +18,10 @@ class UserLogin extends UserEvent{
} }
class LoadLoggedInUser extends UserEvent { class LoadLoggedInUser extends UserEvent {
final UserData? userData; // final UserData? userData;
LoadLoggedInUser({this.userData}); LoadLoggedInUser();
} }
class GetUuid extends UserEvent { class GetUuid extends UserEvent {
GetUuid(); GetUuid();
} }

View File

@ -4,13 +4,14 @@ import 'package:device_preview/device_preview.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:unit2/bloc/bloc/user_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 'package:unit2/utils/global_context.dart'; import 'package:unit2/utils/global_context.dart';
import './utils/router.dart'; import './utils/router.dart';
import './utils/global.dart'; import './utils/global.dart';
void main() { void main() {
runApp(const MyApp()); runApp(MyApp());
} }
// void main() => runApp( // void main() => runApp(
@ -21,12 +22,12 @@ void main() {
// ); // );
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({super.key}); AppRouter? _appRouter;
// This widget is the root of your application. // This widget is the root of your application.
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
BuildContext? parentContext = NavigationService.navigatorKey.currentContext; _appRouter = AppRouter();
final mediaQueryData = final mediaQueryData =
MediaQueryData.fromWindow(WidgetsBinding.instance.window); MediaQueryData.fromWindow(WidgetsBinding.instance.window);
screenWidth = mediaQueryData.size.width; screenWidth = mediaQueryData.size.width;
@ -43,16 +44,16 @@ class MyApp extends StatelessWidget {
return MultiBlocProvider( return MultiBlocProvider(
providers: [ providers: [
BlocProvider( BlocProvider(
create: (parentContext) => UserBloc(), create: (_) => UserBloc(),
), ),
], ],
child: MaterialApp.router( child: MaterialApp(
key: NavigationService.navigatorKey, navigatorKey: NavigationService.navigatorKey,
// useInheritedMediaQuery: true, // useInheritedMediaQuery: true,
// locale: DevicePreview.locale(context), // locale: DevicePreview.locale(context),
// builder: DevicePreview.appBuilder, // builder: DevicePreview.appBuilder,
routeInformationParser: goRouter.routeInformationParser, // routeInformationParser: goRouter.routeInformationParser,
routerDelegate: goRouter.routerDelegate, // routerDelegate: goRouter.routerDelegate,
// routeInformationProvider: goRouter.routeInformationProvider, // routeInformationProvider: goRouter.routeInformationProvider,
title: 'uniT2 - Universal Tracker and Tracer', title: 'uniT2 - Universal Tracker and Tracer',
theme: ThemeData( theme: ThemeData(
@ -64,6 +65,7 @@ class MyApp extends StatelessWidget {
fontFamily: 'LexendDeca', fontFamily: 'LexendDeca',
), ),
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
onGenerateRoute: _appRouter!.onGenerateRoute,
), ),
); );
} }

View File

@ -24,7 +24,9 @@ class _DrawerScreenState extends State<DrawerScreen> {
if (state is UserLoggedIn) { if (state is UserLoggedIn) {
return ZoomDrawer( return ZoomDrawer(
controller: zoomDrawerController, controller: zoomDrawerController,
menuScreen: MenuScreen(userData: state.userData,), menuScreen: MenuScreen(
userData: state.userData,
),
mainScreen: SizedBox( mainScreen: SizedBox(
height: MediaQuery.of(context).size.height, height: MediaQuery.of(context).size.height,
child: const MainScreen()), child: const MainScreen()),
@ -39,7 +41,6 @@ class _DrawerScreenState extends State<DrawerScreen> {
); );
} }
return const UniTSplashScreen(); return const UniTSplashScreen();
}, },
); );
} }

View File

@ -47,7 +47,7 @@ class _UniT2LoginState extends State<UniT2Login> {
print("login" + state.toString()); print("login" + state.toString());
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.dismiss(); progress!.dismiss();
context.goNamed('home', extra: state.userData); Navigator.pushReplacementNamed(context, '/module-screen');
} }
if (state is UuidLoaded) { if (state is UuidLoaded) {
Navigator.push(context, MaterialPageRoute(builder: (context) { Navigator.push(context, MaterialPageRoute(builder: (context) {

View File

@ -1,14 +1,32 @@
// import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
// import 'package:flutter_bloc/flutter_bloc.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{ import '../screens/unit2/homepage.dart/components/drawer-screen.dart';
// Route onGenerateRoute(RouteSettings routeSettings){
// switch(routeSettings.name){ class AppRouter {
// case '/': Route onGenerateRoute(RouteSettings routeSettings) {
// return BlocProvider( switch (routeSettings.name) {
// create: (context) => UserBloc()..add(GetApkVersion()), case '/':
// child: const UniT2Login(), 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();
});
}
}
}

View File

@ -1,78 +1,78 @@
import 'package:flutter/cupertino.dart'; // import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; // import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart'; // import 'package:go_router/go_router.dart';
import 'package:unit2/bloc/bloc/user_bloc.dart'; // import 'package:unit2/bloc/bloc/user_bloc.dart';
import 'package:unit2/model/login_data/user_info/user_data.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/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/scan.dart';
import 'package:unit2/screens/unit2/roles/qr_code_scanner.dart/settings_screen.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/screens/unit2/signature/signature_pad.dart';
import 'package:unit2/utils/global_context.dart'; // import 'package:unit2/utils/global_context.dart';
import 'package:unit2/utils/scanner.dart'; // import 'package:unit2/utils/scanner.dart';
import '../screens/docsms/components/doc_info_tile.dart'; // import '../screens/docsms/components/doc_info_tile.dart';
import '../screens/docsms/request_receipt.dart'; // import '../screens/docsms/request_receipt.dart';
import '../screens/sos/add_mobile.dart'; // import '../screens/sos/add_mobile.dart';
import '../screens/sos/request_sos.dart'; // import '../screens/sos/request_sos.dart';
import '../screens/unit2/login/login.dart'; // import '../screens/unit2/login/login.dart';
import '../screens/unit2/homepage.dart/components/drawer-screen.dart'; // import '../screens/unit2/homepage.dart/components/drawer-screen.dart';
import '../screens/unit2/profile/profile.dart'; // import '../screens/unit2/profile/profile.dart';
import '../screens/unit2/roles/registration_in_charge/home.dart'; // import '../screens/unit2/roles/registration_in_charge/home.dart';
final GoRouter goRouter = GoRouter(routes: <GoRoute>[ // final GoRouter goRouter = GoRouter(routes: <GoRoute>[
GoRoute(
path: '/',
name: 'login',
builder: (context, state) {
return BlocProvider(
create: (context) => UserBloc()..add(GetApkVersion()),
child: const UniT2Login(),
);
},
routes: [
// GoRoute( // GoRoute(
// name: 'qr-login', // path: '/',
// path: 'qr-login', // name: 'login',
// builder: ((context, state) => const QRLogin())), // builder: (context, state) {
GoRoute( // return BlocProvider(
name: 'home', // create: (context) => UserBloc()..add(GetApkVersion()),
path: 'home', // child: const UniT2Login(),
builder: (context, state) { // );
UserData userData = state.extra as UserData; // },
return BlocProvider<UserBloc>.value( // routes: [
value: UserBloc()..add((LoadLoggedInUser(userData: userData))), // // GoRoute(
child: const DrawerScreen(), // // name: 'qr-login',
); // // path: 'qr-login',
}, // // builder: ((context, state) => const QRLogin())),
routes: [ // GoRoute(
GoRoute( // name: 'home',
name: 'profile', // path: 'home',
path: 'profile', // builder: (context, state) {
builder: (context, state) { // UserData userData = state.extra as UserData;
UserData userData = state.extra as UserData; // return BlocProvider<UserBloc>.value(
return BlocProvider<UserBloc>.value( // value: UserBloc()..add((LoadLoggedInUser(userData: userData))),
value: UserBloc() // child: const DrawerScreen(),
..add((LoadLoggedInUser(userData: userData))), // );
child: const Profile(), // },
); // routes: [
}, // GoRoute(
routes: [ // name: 'profile',
GoRoute( // path: 'profile',
name: 'signature', // builder: (context, state) {
path: 'signature', // UserData userData = state.extra as UserData;
builder: (context, state) => const SignaturePad(), // return BlocProvider<UserBloc>.value(
) // value: UserBloc()
]) // ..add((LoadLoggedInUser(userData: userData))),
]), // child: const Profile(),
GoRoute( // );
name: 'add-mobile', // },
path: 'add-moble', // routes: [
builder: (context, state) => AddMobile(), // GoRoute(
routes: [ // name: 'signature',
GoRoute( // path: 'signature',
name: 'request-sos', // builder: (context, state) => const SignaturePad(),
path: 'request-sos', // )
builder: (context, state) => const RequestSOS(), // ])
) // ]),
]), // GoRoute(
]), // name: 'add-mobile',
]); // path: 'add-moble',
// builder: (context, state) => AddMobile(),
// routes: [
// GoRoute(
// name: 'request-sos',
// path: 'request-sos',
// builder: (context, state) => const RequestSOS(),
// )
// ]),
// ]),
// ]);