converted into non go router
parent
c088dbc2a2
commit
226899893f
|
@ -33,17 +33,17 @@ 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();
|
||||||
if(result.rawContent.toString().isNotEmpty){
|
if (result.rawContent.toString().isNotEmpty) {
|
||||||
emit(UuidLoaded(uuid: result.rawContent.toString()));
|
emit(UuidLoaded(uuid: result.rawContent.toString()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,24 +5,23 @@ abstract class UserEvent extends Equatable {
|
||||||
List<Object> get props => [];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetApkVersion extends UserEvent{
|
class GetApkVersion extends UserEvent {
|
||||||
GetApkVersion();
|
GetApkVersion();
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserLogin extends UserEvent{
|
class UserLogin extends UserEvent {
|
||||||
final String? username;
|
final String? username;
|
||||||
final String? password;
|
final String? password;
|
||||||
UserLogin({this.username,this.password});
|
UserLogin({this.username, this.password});
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -39,20 +40,20 @@ class MyApp extends StatelessWidget {
|
||||||
mediaQueryData.padding.top + mediaQueryData.padding.bottom;
|
mediaQueryData.padding.top + mediaQueryData.padding.bottom;
|
||||||
safeBlockHorizontal = (screenWidth - safeAreaHorizontal) / 100;
|
safeBlockHorizontal = (screenWidth - safeAreaHorizontal) / 100;
|
||||||
safeBlockVertical = (screenHeight - safeAreaVertical) / 100;
|
safeBlockVertical = (screenHeight - safeAreaVertical) / 100;
|
||||||
|
|
||||||
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,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,26 +20,27 @@ class _DrawerScreenState extends State<DrawerScreen> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<UserBloc, UserState>(
|
return BlocBuilder<UserBloc, UserState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
print("drawer screen"+state.toString());
|
print("drawer screen" + state.toString());
|
||||||
if(state is UserLoggedIn){
|
if (state is UserLoggedIn) {
|
||||||
return ZoomDrawer(
|
return ZoomDrawer(
|
||||||
controller: zoomDrawerController,
|
controller: zoomDrawerController,
|
||||||
menuScreen: MenuScreen(userData: state.userData,),
|
menuScreen: MenuScreen(
|
||||||
mainScreen: SizedBox(
|
userData: state.userData,
|
||||||
height: MediaQuery.of(context).size.height,
|
),
|
||||||
child: const MainScreen()),
|
mainScreen: SizedBox(
|
||||||
style: DrawerStyle.defaultStyle,
|
height: MediaQuery.of(context).size.height,
|
||||||
borderRadius: 24.0,
|
child: const MainScreen()),
|
||||||
showShadow: false,
|
style: DrawerStyle.defaultStyle,
|
||||||
angle: -0.0,
|
borderRadius: 24.0,
|
||||||
slideWidth: MediaQuery.of(context).size.width * .90,
|
showShadow: false,
|
||||||
openCurve: Curves.fastOutSlowIn,
|
angle: -0.0,
|
||||||
closeCurve: Curves.easeOut,
|
slideWidth: MediaQuery.of(context).size.width * .90,
|
||||||
menuBackgroundColor: Colors.grey,
|
openCurve: Curves.fastOutSlowIn,
|
||||||
);
|
closeCurve: Curves.easeOut,
|
||||||
|
menuBackgroundColor: Colors.grey,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return const UniTSplashScreen();
|
return const UniTSplashScreen();
|
||||||
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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(
|
// GoRoute(
|
||||||
path: '/',
|
// path: '/',
|
||||||
name: 'login',
|
// name: 'login',
|
||||||
builder: (context, state) {
|
// builder: (context, state) {
|
||||||
return BlocProvider(
|
// return BlocProvider(
|
||||||
create: (context) => UserBloc()..add(GetApkVersion()),
|
// create: (context) => UserBloc()..add(GetApkVersion()),
|
||||||
child: const UniT2Login(),
|
// child: const UniT2Login(),
|
||||||
);
|
// );
|
||||||
},
|
// },
|
||||||
routes: [
|
// routes: [
|
||||||
// GoRoute(
|
// // GoRoute(
|
||||||
// name: 'qr-login',
|
// // name: 'qr-login',
|
||||||
// path: 'qr-login',
|
// // path: 'qr-login',
|
||||||
// builder: ((context, state) => const QRLogin())),
|
// // builder: ((context, state) => const QRLogin())),
|
||||||
GoRoute(
|
// GoRoute(
|
||||||
name: 'home',
|
// name: 'home',
|
||||||
path: 'home',
|
// path: 'home',
|
||||||
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()..add((LoadLoggedInUser(userData: userData))),
|
||||||
child: const DrawerScreen(),
|
// child: const DrawerScreen(),
|
||||||
);
|
// );
|
||||||
},
|
// },
|
||||||
routes: [
|
// routes: [
|
||||||
GoRoute(
|
// GoRoute(
|
||||||
name: 'profile',
|
// name: 'profile',
|
||||||
path: 'profile',
|
// 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()
|
// value: UserBloc()
|
||||||
..add((LoadLoggedInUser(userData: userData))),
|
// ..add((LoadLoggedInUser(userData: userData))),
|
||||||
child: const Profile(),
|
// child: const Profile(),
|
||||||
);
|
// );
|
||||||
},
|
// },
|
||||||
routes: [
|
// routes: [
|
||||||
GoRoute(
|
// GoRoute(
|
||||||
name: 'signature',
|
// name: 'signature',
|
||||||
path: 'signature',
|
// path: 'signature',
|
||||||
builder: (context, state) => const SignaturePad(),
|
// builder: (context, state) => const SignaturePad(),
|
||||||
)
|
// )
|
||||||
])
|
// ])
|
||||||
]),
|
// ]),
|
||||||
GoRoute(
|
// GoRoute(
|
||||||
name: 'add-mobile',
|
// name: 'add-mobile',
|
||||||
path: 'add-moble',
|
// path: 'add-moble',
|
||||||
builder: (context, state) => AddMobile(),
|
// builder: (context, state) => AddMobile(),
|
||||||
routes: [
|
// routes: [
|
||||||
GoRoute(
|
// GoRoute(
|
||||||
name: 'request-sos',
|
// name: 'request-sos',
|
||||||
path: 'request-sos',
|
// path: 'request-sos',
|
||||||
builder: (context, state) => const RequestSOS(),
|
// builder: (context, state) => const RequestSOS(),
|
||||||
)
|
// )
|
||||||
]),
|
// ]),
|
||||||
]),
|
// ]),
|
||||||
]);
|
// ]);
|
||||||
|
|
Loading…
Reference in New Issue