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,17 +33,17 @@ 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();
if(result.rawContent.toString().isNotEmpty){
if (result.rawContent.toString().isNotEmpty) {
emit(UuidLoaded(uuid: result.rawContent.toString()));
}
});

View File

@ -5,24 +5,23 @@ abstract class UserEvent extends Equatable {
List<Object> get props => [];
}
class GetApkVersion extends UserEvent{
class GetApkVersion extends UserEvent {
GetApkVersion();
@override
List<Object> get props => [];
}
class UserLogin extends UserEvent{
class UserLogin extends UserEvent {
final String? username;
final String? password;
UserLogin({this.username,this.password});
UserLogin({this.username, this.password});
}
class LoadLoggedInUser extends UserEvent{
final UserData? userData;
LoadLoggedInUser({this.userData});
class LoadLoggedInUser extends UserEvent {
// final UserData? userData;
LoadLoggedInUser();
}
class GetUuid extends UserEvent{
class GetUuid extends UserEvent {
GetUuid();
}

View File

@ -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;
@ -39,20 +40,20 @@ class MyApp extends StatelessWidget {
mediaQueryData.padding.top + mediaQueryData.padding.bottom;
safeBlockHorizontal = (screenWidth - safeAreaHorizontal) / 100;
safeBlockVertical = (screenHeight - safeAreaVertical) / 100;
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,
),
);
}

View File

@ -20,26 +20,27 @@ class _DrawerScreenState extends State<DrawerScreen> {
Widget build(BuildContext context) {
return BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
print("drawer screen"+state.toString());
if(state is UserLoggedIn){
return ZoomDrawer(
controller: zoomDrawerController,
menuScreen: MenuScreen(userData: state.userData,),
mainScreen: SizedBox(
height: MediaQuery.of(context).size.height,
child: const MainScreen()),
style: DrawerStyle.defaultStyle,
borderRadius: 24.0,
showShadow: false,
angle: -0.0,
slideWidth: MediaQuery.of(context).size.width * .90,
openCurve: Curves.fastOutSlowIn,
closeCurve: Curves.easeOut,
menuBackgroundColor: Colors.grey,
);
print("drawer screen" + state.toString());
if (state is UserLoggedIn) {
return ZoomDrawer(
controller: zoomDrawerController,
menuScreen: MenuScreen(
userData: state.userData,
),
mainScreen: SizedBox(
height: MediaQuery.of(context).size.height,
child: const MainScreen()),
style: DrawerStyle.defaultStyle,
borderRadius: 24.0,
showShadow: false,
angle: -0.0,
slideWidth: MediaQuery.of(context).size.width * .90,
openCurve: Curves.fastOutSlowIn,
closeCurve: Curves.easeOut,
menuBackgroundColor: Colors.grey,
);
}
return const UniTSplashScreen();
return const UniTSplashScreen();
},
);
}

View File

@ -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) {

View File

@ -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();
});
}
}
}

View File

@ -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: [
// 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(),
)
]),
]),
]);
// 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(
// // 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(),
// )
// ]),
// ]),
// ]);