diff --git a/unit2/lib/bloc/bloc/user_bloc.dart b/unit2/lib/bloc/bloc/user_bloc.dart index 34b651b..2a8c144 100644 --- a/unit2/lib/bloc/bloc/user_bloc.dart +++ b/unit2/lib/bloc/bloc/user_bloc.dart @@ -1,3 +1,4 @@ +import 'package:barcode_scan2/barcode_scan2.dart'; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; @@ -6,15 +7,17 @@ import 'package:unit2/model/login_data/version_info.dart'; import 'package:unit2/sevices/login_service/auth_service.dart'; import 'package:unit2/widgets/error_state.dart'; +import '../../utils/scanner.dart'; + part 'user_event.dart'; part 'user_state.dart'; class UserBloc extends Bloc { + UserData? _userData; UserBloc() : super(UserInitial()) { // this event is called when opening the app to check if // there is new app version on((event, emit) async { - debugPrint("getApkEvent is called"); try { emit(SplashScreen()); VersionInfo versionInfo = await AuthService.instance.getVersionInfo(); @@ -24,14 +27,25 @@ class UserBloc extends Bloc { message: e.toString(), )); } - on((event, emit) async{ - try{ - UserData? userData = await AuthService.instance.webLogin(username: event.username,password: event.password); - emit(UserLoggedIn(userData: userData)); - }catch(e){ - emit(UserError(message: e.toString())); - } - }); + }); + on((event, emit) async { + try { + UserData? userData = await AuthService.instance + .webLogin(username: event.username, password: event.password); + _userData = userData; + emit(UserLoggedIn(userData: userData)); + } catch (e) { + emit(UserError(message: e.toString())); + } + }); + on((event, emit) { + emit(UserLoggedIn(userData: event.userData)); + }); + on((event, emit) async { + ScanResult result = await QRCodeBarCodeScanner.instance.scanner(); + if(result.rawContent.toString().isNotEmpty){ + emit(UuidLoaded(uuid: result.rawContent.toString())); + } }); } } diff --git a/unit2/lib/bloc/bloc/user_event.dart b/unit2/lib/bloc/bloc/user_event.dart index 85a66d2..019edbc 100644 --- a/unit2/lib/bloc/bloc/user_event.dart +++ b/unit2/lib/bloc/bloc/user_event.dart @@ -1,13 +1,12 @@ part of 'user_bloc.dart'; abstract class UserEvent extends Equatable { - const UserEvent(); - @override List get props => []; } class GetApkVersion extends UserEvent{ + GetApkVersion(); @override List get props => []; } @@ -15,5 +14,15 @@ class GetApkVersion extends UserEvent{ class UserLogin extends UserEvent{ final String? username; final String? password; - const UserLogin({this.username,this.password}); + UserLogin({this.username,this.password}); +} + +class LoadLoggedInUser extends UserEvent{ + final UserData? userData; + LoadLoggedInUser({this.userData}); +} + +class GetUuid extends UserEvent{ + + GetUuid(); } diff --git a/unit2/lib/bloc/bloc/user_state.dart b/unit2/lib/bloc/bloc/user_state.dart index 608f899..2c5b56b 100644 --- a/unit2/lib/bloc/bloc/user_state.dart +++ b/unit2/lib/bloc/bloc/user_state.dart @@ -1,17 +1,20 @@ part of 'user_bloc.dart'; abstract class UserState extends Equatable { - const UserState(); @override List get props => []; } -class UserInitial extends UserState {} +class UserInitial extends UserState { + UserInitial(); + @override + List get props => []; +} class UserLoading extends UserState { final String? message; - const UserLoading({this.message}); + UserLoading({this.message}); @override List get props => [message!]; } @@ -23,18 +26,24 @@ class SplashScreen extends UserState { class UserError extends UserState { final String? message; - const UserError({this.message}); + UserError({this.message}); @override List get props => []; } class UserLoggedIn extends UserState{ final UserData? userData; - const UserLoggedIn({this.userData}); + UserLoggedIn({this.userData}); } class VersionLoaded extends UserState { final VersionInfo? versionInfo; - const VersionLoaded({this.versionInfo}); + VersionLoaded({this.versionInfo}); @override List get props => [versionInfo!]; } +class UuidLoaded extends UserState{ + final String uuid; + UuidLoaded({required this.uuid}); + @override + List get props => [uuid]; +} diff --git a/unit2/lib/main.dart b/unit2/lib/main.dart index af6b45d..9ff8fb7 100644 --- a/unit2/lib/main.dart +++ b/unit2/lib/main.dart @@ -4,6 +4,8 @@ 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/global_context.dart'; +import 'package:unit2/utils/global_context.dart'; import './utils/router.dart'; import './utils/global.dart'; @@ -24,6 +26,7 @@ class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { + BuildContext? parentContext = NavigationService.navigatorKey.currentContext; final mediaQueryData = MediaQueryData.fromWindow(WidgetsBinding.instance.window); screenWidth = mediaQueryData.size.width; @@ -36,10 +39,15 @@ class MyApp extends StatelessWidget { mediaQueryData.padding.top + mediaQueryData.padding.bottom; safeBlockHorizontal = (screenWidth - safeAreaHorizontal) / 100; safeBlockVertical = (screenHeight - safeAreaVertical) / 100; - - return BlocProvider( - create: (context) => UserBloc(), + + return MultiBlocProvider( + providers: [ + BlocProvider( + create: (parentContext) => UserBloc(), + ), + ], child: MaterialApp.router( + key: NavigationService.navigatorKey, // useInheritedMediaQuery: true, // locale: DevicePreview.locale(context), // builder: DevicePreview.appBuilder, diff --git a/unit2/lib/screens/unit2/homepage.dart/components/dashboard.dart b/unit2/lib/screens/unit2/homepage.dart/components/dashboard.dart new file mode 100644 index 0000000..c5c9ec9 --- /dev/null +++ b/unit2/lib/screens/unit2/homepage.dart/components/dashboard.dart @@ -0,0 +1,81 @@ +import 'package:flutter/material.dart'; +import 'package:unit2/screens/unit2/homepage.dart/module-screen.dart'; + +import 'package:unit2/test_data.dart'; +import 'package:unit2/theme-data.dart/colors.dart'; + +class DashBoard extends StatelessWidget { + final List roles; + const DashBoard({super.key, required this.roles}); + @override + Widget build(BuildContext context) { + return Container( + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 24), + height: MediaQuery.of(context).size.height, + //listview builder + child: ListView.builder( + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: roles.length, + itemBuilder: (BuildContext context, int index) { + // gridview.count + return SizedBox( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + roles[index].name, + style: Theme.of(context) + .textTheme + .labelLarge! + .copyWith(fontSize: 16, fontWeight: FontWeight.w700), + ), + const Divider(), + const SizedBox( + height: 8, + ), + GridView.count( + shrinkWrap: true, + crossAxisCount: 4, + crossAxisSpacing: 5, + mainAxisSpacing: 2, + physics: const BouncingScrollPhysics(), + padding: const EdgeInsets.symmetric( + vertical: 5, horizontal: 5), + children: roles[index].roles.map((role) { + return GestureDetector( + onTap: () { + print("Role is click"); + }, + child: Column(children: [ + Icon( + role.icon, + size: 24, + color: second, + ), + const SizedBox( + height: 5, + ), + Expanded( + child: Text( + role.role.name!, + textAlign: TextAlign.center, + style: Theme.of(context) + .textTheme + .button! + .copyWith( + fontSize: 11, + fontWeight: FontWeight.bold), + ), + ), + ]), + ); + }).toList()), + ], + ), + ); + }), + ); + } +} diff --git a/unit2/lib/screens/unit2/homepage.dart/components/drawer-screen.dart b/unit2/lib/screens/unit2/homepage.dart/components/drawer-screen.dart index 4ffd092..78d1014 100644 --- a/unit2/lib/screens/unit2/homepage.dart/components/drawer-screen.dart +++ b/unit2/lib/screens/unit2/homepage.dart/components/drawer-screen.dart @@ -1,7 +1,10 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_zoom_drawer/config.dart'; import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart'; +import 'package:unit2/bloc/bloc/user_bloc.dart'; import 'package:unit2/theme-data.dart/colors.dart'; +import '../../../../widgets/splash_screen.dart'; import 'menu-screen.dart'; import '../module-screen.dart'; @@ -15,18 +18,29 @@ class _DrawerScreenState extends State { final zoomDrawerController = ZoomDrawerController(); @override Widget build(BuildContext context) { - return ZoomDrawer( - controller: zoomDrawerController, - menuScreen: const MenuScreen(), - mainScreen: 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 BlocBuilder( + 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, + ); + } + return const UniTSplashScreen(); + + }, ); } } diff --git a/unit2/lib/screens/unit2/homepage.dart/components/menu-screen.dart b/unit2/lib/screens/unit2/homepage.dart/components/menu-screen.dart index e9f722a..1145405 100644 --- a/unit2/lib/screens/unit2/homepage.dart/components/menu-screen.dart +++ b/unit2/lib/screens/unit2/homepage.dart/components/menu-screen.dart @@ -3,11 +3,13 @@ import 'package:unit2/theme-data.dart/colors.dart'; import 'package:fluttericon/web_symbols_icons.dart'; import 'package:fluttericon/typicons_icons.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; +import '../../../../model/login_data/user_info/user_data.dart'; import 'menu.dart'; import '../../../../utils/global.dart'; class MenuScreen extends StatefulWidget { - const MenuScreen({Key? key}) : super(key: key); + final UserData? userData; + const MenuScreen({Key? key, required this.userData}) : super(key: key); @override State createState() => _MenuScreenState(); @@ -16,6 +18,10 @@ class MenuScreen extends StatefulWidget { class _MenuScreenState extends State { @override Widget build(BuildContext context) { + final String firstName = + widget.userData!.user!.login!.user!.firstName!.toUpperCase(); + final String lastname = + widget.userData!.user!.login!.user!.lastName!.toUpperCase(); return SafeArea( child: Drawer( child: SingleChildScrollView( @@ -24,13 +30,13 @@ class _MenuScreenState extends State { child: Column( // ignore: prefer_const_literals_to_create_immutables children: [ - const UserAccountsDrawerHeader( - decoration: BoxDecoration( + UserAccountsDrawerHeader( + decoration: const BoxDecoration( color: primary, image: DecorationImage( image: AssetImage('assets/pngs/bg.png'), fit: BoxFit.cover)), - accountName: Text("ACUIN" ", " "RODOLFO" " " "BERNALIS"), + accountName: Text("$firstName $lastname"), accountEmail: null, currentAccountPicture: CircleAvatar( radius: 40, @@ -40,30 +46,26 @@ class _MenuScreenState extends State { backgroundColor: third, child: //Icon(Icons.person, size: 40, color: fifth), Text( - "A", - style: TextStyle(fontSize: 45.0, color: fifth), + firstName[0].toUpperCase(), + style: const TextStyle(fontSize: 45.0, color: fifth), ), ), ), ), - getTile(Typicons.user_outline, "Profile", 'profile', context), + getTile(FontAwesome5.user, "Basic Info", 'profile', context, + widget.userData!), const Divider(), - getTile(Typicons.home_outline, "Address", '/SelfAddressScreen', - context), - const Divider(), - getTile(Typicons.contacts, "Contact Number", - '/SelfContactScreen', context), - const Divider(), - getTile(Typicons.mail, "Email Address", '/SelfEmailAddScreen', - context), + getTile(FontAwesome5.user_circle, "Profile", + '/SelfAddressScreen', context, widget.userData!), const Divider(), getTile(FontAwesome5.life_ring, "Request SOS", 'request-sos', - context), + context, widget.userData!), const Divider(), Expanded( child: Align( alignment: FractionalOffset.bottomLeft, - child: getTile(WebSymbols.logout, "Logout", 'login', context), + child: getTile(WebSymbols.logout, "Logout", 'login', context, + widget.userData!), )), ], ), diff --git a/unit2/lib/screens/unit2/homepage.dart/components/menu.dart b/unit2/lib/screens/unit2/homepage.dart/components/menu.dart index cdfbd44..7c2544d 100644 --- a/unit2/lib/screens/unit2/homepage.dart/components/menu.dart +++ b/unit2/lib/screens/unit2/homepage.dart/components/menu.dart @@ -1,11 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart'; import 'package:go_router/go_router.dart'; +import 'package:unit2/model/login_data/user_info/user_data.dart'; import 'package:unit2/utils/alerts.dart'; import '../../../../theme-data.dart/colors.dart'; Widget getTile( - IconData icondata, String title, String route, BuildContext context) { + IconData icondata, String title, String route, BuildContext context,UserData userData) { return ListTile( dense: true, leading: Icon( @@ -22,7 +23,7 @@ Widget getTile( context.goNamed("login"); }); } else { - context.goNamed(route); + context.goNamed(route,extra: userData); } }, ); diff --git a/unit2/lib/screens/unit2/homepage.dart/module-screen.dart b/unit2/lib/screens/unit2/homepage.dart/module-screen.dart index 96b7a99..f741589 100644 --- a/unit2/lib/screens/unit2/homepage.dart/module-screen.dart +++ b/unit2/lib/screens/unit2/homepage.dart/module-screen.dart @@ -1,8 +1,16 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart'; +import 'package:fluttericon/font_awesome5_icons.dart'; +import 'package:fluttericon/font_awesome_icons.dart'; +import 'package:fluttericon/typicons_icons.dart'; +import 'package:unit2/screens/unit2/homepage.dart/components/dashboard.dart'; +import 'package:unit2/test_data.dart'; import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/utils/text_container.dart'; +import '../../../bloc/bloc/user_bloc.dart'; +import '../../../model/login_data/user_info/role.dart'; import 'components/empty_module.dart'; class MainScreen extends StatefulWidget { @@ -13,41 +21,98 @@ class MainScreen extends StatefulWidget { } class _MainScreenState extends State { - bool hasModule = false; + List roles = [ + Module(name: 'UniT2 roles', roles: []), + Module(name: 'DocSms roles', roles: []) + ]; @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async { return Future.value(true); }, - child: SafeArea( - child: Scaffold( - appBar: AppBar( - backgroundColor: primary, - leading: IconButton( - onPressed: () { - ZoomDrawer.of(context)!.toggle(); - }, - icon: const Icon( - Icons.menu, - color: Colors.white, + child: BlocBuilder(builder: (context, state) { + if (state is UserLoggedIn) { + state.userData!.user!.login!.user!.roles!.forEach((role) { + Role? getRole = role; + role!.modules!.forEach((module) { + if (module!.name!.toLowerCase() == 'unit2') { + IconData iconData = iconGenerator(getRole!.name!); + Roles newRole = Roles(role: getRole, icon: iconData); + roles[0].roles.add(newRole); + } + if (module.name!.toLowerCase() == 'document management') { + IconData iconData = iconGenerator(getRole!.name!); + Roles newRole = Roles(role: getRole, icon: iconData); + roles[1].roles.add(newRole); + } + }); + }); + return SafeArea( + child: Scaffold( + appBar: AppBar( + backgroundColor: primary, + leading: IconButton( + onPressed: () { + ZoomDrawer.of(context)!.toggle(); + }, + icon: const Icon( + Icons.menu, + color: Colors.white, + ), + ), + centerTitle: true, + title: const Text( + unit2ModuleScreen, + style: TextStyle( + fontSize: 18.0, + color: Colors.white, + ), + ), ), - ), - centerTitle: true, - title: const Text( - unit2ModuleScreen, - style: TextStyle( - fontSize: 18.0, - color: Colors.white, - ), - ), - ), - body: hasModule - ? const Center( - child: Text('Main Screen'), - ) - : const NoModule(), - )), + body: state.userData!.user!.login!.user!.roles!.isNotEmpty + ? DashBoard( + roles: roles, + ) + : const NoModule(), + )); + } + return Container(); + }), ); } + + IconData iconGenerator(String roleName) { + IconData? iconData; + switch (roleName.toLowerCase()) { + case 'qr code scanner': + iconData = FontAwesome.qrcode; + break; + case 'security guard': + iconData = FontAwesome5.user_shield; + break; + case 'establishment point-person': + iconData = FontAwesome.building_filled; + break; + case 'registration in-charge': + iconData = FontAwesome.user_plus; + break; + case 'process server': + iconData = Typicons.doc_text; + break; + } + return iconData!; + } +} + +class Module { + final String name; + final List roles; + Module({required this.name, required this.roles}); +} + +class Roles { + final IconData icon; + final Role role; + Roles({required this.role, required this.icon}); } diff --git a/unit2/lib/screens/unit2/login/login.dart b/unit2/lib/screens/unit2/login/login.dart index e527582..b1ff3ec 100644 --- a/unit2/lib/screens/unit2/login/login.dart +++ b/unit2/lib/screens/unit2/login/login.dart @@ -4,14 +4,18 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:go_router/go_router.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.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/utils/text_container.dart'; import 'package:unit2/widgets/error_state.dart'; +import '../../../utils/scanner.dart'; import '../../../widgets/splash_screen.dart'; import '../../../widgets/wave.dart'; import '../../../utils/global.dart'; @@ -40,9 +44,15 @@ class _UniT2LoginState extends State { body: ProgressHUD( child: BlocConsumer(listener: (context, state) { if (state is UserLoggedIn) { + print("login" + state.toString()); final progress = ProgressHUD.of(context); progress!.dismiss(); - debugPrint(state.userData!.user!.login!.user!.firstName); + context.goNamed('home', extra: state.userData); + } + if (state is UuidLoaded) { + Navigator.push(context, MaterialPageRoute(builder: (context) { + return QRLogin(); + })); } }, builder: (context, state) { if (state is VersionLoaded) { @@ -50,6 +60,7 @@ class _UniT2LoginState extends State { return SizedBox( child: SingleChildScrollView( child: Stack( + alignment: Alignment.center, children: [ Positioned( bottom: 0, @@ -64,11 +75,11 @@ class _UniT2LoginState extends State { const EdgeInsets.symmetric(horizontal: 25), child: Column( crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, children: [ - SizedBox(height: blockSizeVertical * 7), SvgPicture.asset( 'assets/svgs/logo.svg', - height: blockSizeVertical * 16, + height: blockSizeVertical * 12, allowDrawingOutsideViewBox: true, color: primary, ), @@ -76,25 +87,25 @@ class _UniT2LoginState extends State { Text( welcome, style: TextStyle( - fontSize: blockSizeVertical * 5, + fontSize: blockSizeVertical * 4, fontWeight: FontWeight.w600), ), Text(unitApp, style: TextStyle( - fontSize: blockSizeVertical * 8, + fontSize: blockSizeVertical * 6, fontWeight: FontWeight.w800, letterSpacing: .2, height: 1, color: primary)), - Text( - loginToContinue, - style: TextStyle( - fontSize: blockSizeVertical * 2, - height: 1.5, - fontWeight: FontWeight.w600), - ), + // Text( + // loginToContinue, + // style: TextStyle( + // fontSize: blockSizeVertical * 1.7, + // height: 1.5, + // fontWeight: FontWeight.w600), + // ), SizedBox( - height: blockSizeVertical * 1.5, + height: blockSizeVertical * 3, ), // USERNAME FormBuilderTextField( @@ -243,17 +254,10 @@ class _UniT2LoginState extends State { loginViaQr, style: TextStyle(color: second), ), - onPressed: () async { - context.goNamed('register'); - // ScanResult result = - // await QRCodeBarCodeScanner.instance - // .scanner(); - - // debugPrint(result.type.toString()); - // debugPrint( - // result.rawContent.toString()); - // BlocProvider.of(context) - // .add(QRCodelogin()); + onPressed: () { + context + .read() + .add(GetUuid()); }, ), )), @@ -302,9 +306,7 @@ class _UniT2LoginState extends State { if (state is SplashScreen) { return const UniTSplashScreen(); } - return const Center( - child: Text("Default"), - ); + return Container(); }), ), ), diff --git a/unit2/lib/screens/unit2/login/qr_login.dart b/unit2/lib/screens/unit2/login/qr_login.dart new file mode 100644 index 0000000..fbbd3ae --- /dev/null +++ b/unit2/lib/screens/unit2/login/qr_login.dart @@ -0,0 +1,239 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/container.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_form_builder/flutter_form_builder.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:fluttericon/font_awesome5_icons.dart'; +import 'package:fluttericon/font_awesome_icons.dart'; +import 'package:form_builder_validators/form_builder_validators.dart'; +import 'package:go_router/go_router.dart'; +import 'package:unit2/theme-data.dart/btn-style.dart'; +import 'package:unit2/widgets/wave.dart'; + +import '../../../bloc/bloc/user_bloc.dart'; +import '../../../theme-data.dart/colors.dart'; +import '../../../theme-data.dart/form-style.dart'; +import '../../../utils/global.dart'; +import '../../../utils/text_container.dart'; +import '../../../utils/validators.dart'; + +class QRLogin extends StatefulWidget { + const QRLogin({super.key}); + + @override + State createState() => _QRLoginState(); +} + +class _QRLoginState extends State { + bool showSuffixIcon = false; + bool _showPassword = true; + final _formKey = GlobalKey(); + @override + Widget build(BuildContext context) { + return SafeArea( + child: Scaffold( + resizeToAvoidBottomInset: true, + appBar: AppBar( + backgroundColor: primary, + elevation: 0, + automaticallyImplyLeading: true, + title: const Text("Login via QR"), + centerTitle: true, + ), + body: BlocBuilder( + builder: (context, state) { + print(state); + if (state is UuidLoaded) { + return Center( + child: Text(state.uuid), + ); + } + return SingleChildScrollView( + child: Stack( + children: [ + Positioned( + bottom: 0, + child: WaveReverse(height: blockSizeVertical * 8)), + Container( + height: screenHeight * .90, + padding: const EdgeInsets.symmetric(horizontal: 15), + child: FormBuilder( + key: _formKey, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SvgPicture.asset( + 'assets/svgs/logo.svg', + height: blockSizeVertical * 12, + allowDrawingOutsideViewBox: true, + color: primary, + ), + const SizedBox( + height: 12, + ), + Text(unitApp, + style: TextStyle( + fontSize: blockSizeVertical * 5, + fontWeight: FontWeight.w800, + letterSpacing: .2, + height: 1, + color: Colors.black87)), + const SizedBox( + height: 15, + ), + Text( + "Enter your password", + style: TextStyle( + fontSize: blockSizeVertical * 1.5, + height: 1.5, + fontWeight: FontWeight.w600), + ), + const SizedBox( + height: 15, + ), + // Password + FormBuilderTextField( + name: 'password', + validator: registerPasswordValidator, + // initialValue: state.password, + onChanged: (value) { + value!.isEmpty + ? setState(() { + showSuffixIcon = false; + }) + : setState(() { + showSuffixIcon = true; + }); + }, + autofocus: false, + style: const TextStyle( + fontWeight: FontWeight.bold, + color: Colors.black87), + decoration: loginTextFieldStyle().copyWith( + suffixIcon: Visibility( + visible: showSuffixIcon, + child: _showPassword + ? IconButton( + icon: Icon(FontAwesome5.eye_slash, + size: 24, + color: Theme.of(context) + .textTheme + .displayLarge + ?.color), + onPressed: () { + setState(() { + _showPassword = false; + }); + }, + ) + : IconButton( + onPressed: () { + setState(() { + _showPassword = true; + }); + }, + icon: Icon(FontAwesome5.eye, + size: 24, + color: Theme.of(context) + .textTheme + .displayLarge + ?.color)), + ), + prefixIcon: const Icon(Icons.lock), + labelText: "Password", + hintText: enterPassword), + obscureText: _showPassword ? true : false, + ), + const SizedBox( + height: 15, + ), + // FormBuilderTextField( + // name: 'confirmPassword', + // validator: registerPasswordValidator, + // // initialValue: state.password, + // onChanged: (value) { + // value!.isEmpty + // ? setState(() { + // showSuffixIcon = false; + // }) + // : setState(() { + // showSuffixIcon = true; + // }); + // }, + // autofocus: false, + // style: const TextStyle( + // fontWeight: FontWeight.bold, color: Colors.black87), + // decoration: loginTextFieldStyle().copyWith( + // suffixIcon: Visibility( + // visible: showSuffixIcon, + // child: _showPassword + // ? IconButton( + // icon: Icon(FontAwesome5.eye_slash, + // size: 24, + // color: Theme.of(context) + // .textTheme + // .displayLarge + // ?.color), + // onPressed: () { + // setState(() { + // _showPassword = false; + // }); + // }, + // ) + // : IconButton( + // onPressed: () { + // setState(() { + // _showPassword = true; + // }); + // }, + // icon: Icon(FontAwesome5.eye, + // size: 24, + // color: Theme.of(context) + // .textTheme + // .displayLarge + // ?.color)), + // ), + // prefixIcon: const Icon(Icons.lock), + // labelText: confirmPassword, + // hintText: enterConfirmPassword), + // obscureText: _showPassword ? true : false, + // ), + const SizedBox( + height: 15, + ), + SizedBox( + width: double.infinity, + height: blockSizeVertical * 6, + child: ElevatedButton( + style: secondaryBtnStyle( + second, Colors.transparent, primary), + onPressed: () { + if (_formKey.currentState! + .saveAndValidate()) { + BlocProvider.of(context) + .add(UserLogin( + username: _formKey + .currentState!.value['username'], + password: _formKey + .currentState!.value['password'], + )); + } + }, + child: const Text(submit)), + ) + ], + ), + ), + ), + ], + ), + ); + }, + ), + ), + ); + } +} diff --git a/unit2/lib/screens/unit2/login/register.dart b/unit2/lib/screens/unit2/login/register.dart deleted file mode 100644 index 0468000..0000000 --- a/unit2/lib/screens/unit2/login/register.dart +++ /dev/null @@ -1,213 +0,0 @@ -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/src/widgets/container.dart'; -import 'package:flutter/src/widgets/framework.dart'; -import 'package:flutter_form_builder/flutter_form_builder.dart'; -import 'package:flutter_svg/svg.dart'; -import 'package:fluttericon/font_awesome5_icons.dart'; -import 'package:fluttericon/font_awesome_icons.dart'; -import 'package:form_builder_validators/form_builder_validators.dart'; -import 'package:go_router/go_router.dart'; -import 'package:unit2/theme-data.dart/btn-style.dart'; -import 'package:unit2/widgets/wave.dart'; - -import '../../../theme-data.dart/colors.dart'; -import '../../../theme-data.dart/form-style.dart'; -import '../../../utils/global.dart'; -import '../../../utils/text_container.dart'; -import '../../../utils/validators.dart'; - -class Register extends StatefulWidget { - const Register({super.key}); - - @override - State createState() => _RegisterState(); -} - -class _RegisterState extends State { - bool showSuffixIcon = false; - bool _showPassword = true; - final _formKey = GlobalKey(); - @override - Widget build(BuildContext context) { - return SafeArea( - child: Scaffold( - resizeToAvoidBottomInset: true, - appBar: AppBar( - backgroundColor: primary, - elevation: 0, - automaticallyImplyLeading: true, - title: const Text("Register password"), - centerTitle: true, - ), - body: SingleChildScrollView( - child: Stack( - children: [ - Wave(height: blockSizeVertical * 8), - Positioned( - bottom: 0, child: WaveReverse(height: blockSizeVertical * 8)), - Container( - height: screenHeight * .90, - padding: const EdgeInsets.symmetric(horizontal: 15), - child: FormBuilder( - key: _formKey, - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SvgPicture.asset( - 'assets/svgs/logo.svg', - height: blockSizeVertical * 16, - allowDrawingOutsideViewBox: true, - color: primary, - ), - Text(unitApp, - style: TextStyle( - fontSize: blockSizeVertical * 8, - fontWeight: FontWeight.w800, - letterSpacing: .2, - height: 1, - color: Colors.black87)), - Text( - registerToContinue, - style: TextStyle( - fontSize: blockSizeVertical * 2, - height: 1.5, - fontWeight: FontWeight.w600), - ), - const SizedBox( - height: 15, - ), - // Password - FormBuilderTextField( - name: 'password', - validator: registerPasswordValidator, - // initialValue: state.password, - onChanged: (value) { - value!.isEmpty - ? setState(() { - showSuffixIcon = false; - }) - : setState(() { - showSuffixIcon = true; - }); - }, - autofocus: false, - style: const TextStyle( - fontWeight: FontWeight.bold, color: Colors.black87), - decoration: loginTextFieldStyle().copyWith( - suffixIcon: Visibility( - visible: showSuffixIcon, - child: _showPassword - ? IconButton( - icon: Icon(FontAwesome5.eye_slash, - size: 24, - color: Theme.of(context) - .textTheme - .displayLarge - ?.color), - onPressed: () { - setState(() { - _showPassword = false; - }); - }, - ) - : IconButton( - onPressed: () { - setState(() { - _showPassword = true; - }); - }, - icon: Icon(FontAwesome5.eye, - size: 24, - color: Theme.of(context) - .textTheme - .displayLarge - ?.color)), - ), - prefixIcon: const Icon(Icons.lock), - labelText: "Password", - hintText: enterPassword), - obscureText: _showPassword ? true : false, - ), - const SizedBox( - height: 15, - ), - FormBuilderTextField( - name: 'confirmPassword', - validator: registerPasswordValidator, - // initialValue: state.password, - onChanged: (value) { - value!.isEmpty - ? setState(() { - showSuffixIcon = false; - }) - : setState(() { - showSuffixIcon = true; - }); - }, - autofocus: false, - style: const TextStyle( - fontWeight: FontWeight.bold, color: Colors.black87), - decoration: loginTextFieldStyle().copyWith( - suffixIcon: Visibility( - visible: showSuffixIcon, - child: _showPassword - ? IconButton( - icon: Icon(FontAwesome5.eye_slash, - size: 24, - color: Theme.of(context) - .textTheme - .displayLarge - ?.color), - onPressed: () { - setState(() { - _showPassword = false; - }); - }, - ) - : IconButton( - onPressed: () { - setState(() { - _showPassword = true; - }); - }, - icon: Icon(FontAwesome5.eye, - size: 24, - color: Theme.of(context) - .textTheme - .displayLarge - ?.color)), - ), - prefixIcon: const Icon(Icons.lock), - labelText: confirmPassword, - hintText: enterConfirmPassword), - obscureText: _showPassword ? true : false, - ), - const SizedBox( - height: 15, - ), - SizedBox( - width: double.infinity, - height: blockSizeVertical * 6, - child: ElevatedButton( - style: secondaryBtnStyle( - second, Colors.transparent, primary), - onPressed: () { - if (_formKey.currentState!.saveAndValidate()) { - context.goNamed('home'); - } - }, - child: const Text(register)), - ) - ], - ), - ), - ), - ], - ), - ), - ), - ); - } -} diff --git a/unit2/lib/screens/unit2/profile/profile.dart b/unit2/lib/screens/unit2/profile/profile.dart index 33cfec9..b0004f5 100644 --- a/unit2/lib/screens/unit2/profile/profile.dart +++ b/unit2/lib/screens/unit2/profile/profile.dart @@ -1,14 +1,19 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_svg/svg.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; -import 'package:fluttericon/web_symbols_icons.dart'; import 'package:go_router/go_router.dart'; +import 'package:intl/intl.dart'; import 'package:qr_flutter/qr_flutter.dart'; +import 'package:unit2/bloc/bloc/user_bloc.dart'; +import 'package:unit2/model/login_data/user_info/user_data.dart'; import 'package:unit2/test_data.dart'; import 'package:unit2/theme-data.dart/btn-style.dart'; import 'package:unit2/utils/global.dart'; import 'package:unit2/utils/text_container.dart'; import '../../../theme-data.dart/colors.dart'; +import '../../../widgets/splash_screen.dart'; import './components/cover-image.dart'; class Profile extends StatelessWidget { @@ -20,69 +25,81 @@ class Profile extends StatelessWidget { onWillPop: () async { return Future.value(true); }, - child: SafeArea( - child: Scaffold( - body: SizedBox( - width: screenWidth, - child: Column( - children: [ - Stack( - clipBehavior: Clip.none, - alignment: Alignment.center, - children: [ - const CoverImage(), - Positioned( - top: blockSizeVertical * 17.5, - child: Stack( - alignment: Alignment.center, - children: [ - const CircleAvatar( - radius: 72, - backgroundColor: Colors.white, - ), - CircleAvatar( - radius: 69, - backgroundColor: Colors.grey.shade800, - child: SvgPicture.asset( - 'assets/svgs/male.svg', + child: ProgressHUD( + child: BlocBuilder( + builder: (context, state) { + if (state is UserLoggedIn) { + state.userData!.employeeInfo!.profile!.sex!.toUpperCase(); + return SafeArea( + child: Scaffold( + body: SizedBox( + width: screenWidth, + child: Column( + children: [ + Stack( + clipBehavior: Clip.none, + alignment: Alignment.center, + children: [ + const CoverImage(), + Positioned( + top: blockSizeVertical * 17.5, + child: Stack( + alignment: Alignment.center, + children: [ + const CircleAvatar( + radius: 72, + backgroundColor: Colors.white, + ), + CircleAvatar( + radius: 69, + backgroundColor: Colors.grey.shade800, + child: SvgPicture.asset( + 'assets/svgs/male.svg', + ), + ), + ], + ), ), - ), - ], - ), + Positioned( + top: 10, + left: 20, + child: IconButton( + onPressed: () { + Navigator.pop(context); + }, + icon: const Icon( + FontAwesome5.arrow_left, + size: 24, + color: Colors.white, + ), + )), + Positioned( + top: 10, + right: 20, + child: IconButton( + onPressed: () {}, + icon: const Icon( + Icons.edit, + size: 24, + color: Colors.white, + ), + )), + ], + ), + SizedBox( + height: blockSizeVertical * 5, + ), + BuildInformation( + userData: state.userData!, + ), + ], ), - Positioned( - top: 10, - left: 20, - child: IconButton( - onPressed: () { - context.go(context.namedLocation('home')); - }, - icon: const Icon( - FontAwesome5.arrow_left, - size: 24, - color: Colors.white, - ), - )), - Positioned( - top: 10, - right: 20, - child: IconButton( - onPressed: () {}, - icon: const Icon( - Icons.edit, - size: 24, - color: Colors.white, - ), - )), - ], + ), ), - SizedBox( - height: blockSizeVertical * 5, - ), - const BuildInformation(), - ], - ), - ), + ); + } + return const UniTSplashScreen(); + }, ), ), ); @@ -90,9 +107,19 @@ class Profile extends StatelessWidget { } class BuildInformation extends StatelessWidget { - const BuildInformation({super.key}); + final UserData userData; + const BuildInformation({super.key, required this.userData}); @override Widget build(BuildContext context) { + DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); + final String firstName = + userData.user!.login!.user!.firstName!.toUpperCase(); + final String lastname = userData.user!.login!.user!.lastName!.toUpperCase(); + final String middlename = + userData.employeeInfo!.profile!.middleName!.toUpperCase(); + final String sex = userData.employeeInfo!.profile!.sex!.toUpperCase(); + final DateTime? bday = userData.employeeInfo!.profile!.birthdate; + final uuid = userData.employeeInfo!.uuid; return Container( padding: const EdgeInsets.symmetric(horizontal: 25), width: screenWidth, @@ -102,7 +129,8 @@ class BuildInformation extends StatelessWidget { height: 25, ), Text( - "Rodolfo Bernales Acuin", + "$firstName $middlename $lastname", + textAlign: TextAlign.center, style: Theme.of(context) .textTheme .headline5! @@ -112,14 +140,14 @@ class BuildInformation extends StatelessWidget { height: 10, ), Text( - "july 14, 1994 | Male", + "${dteFormat2.format(bday!)} | $sex", style: Theme.of(context).textTheme.caption!.copyWith(fontSize: 18), ), const SizedBox( height: 15, ), QrImage( - data: uuid, + data: uuid!, size: blockSizeVertical * 30, ), const SizedBox( diff --git a/unit2/lib/test_data.dart b/unit2/lib/test_data.dart index 47714c3..566f446 100644 --- a/unit2/lib/test_data.dart +++ b/unit2/lib/test_data.dart @@ -1,5 +1,10 @@ import 'package:azlistview/azlistview.dart'; -String uuid = 'f68c3142-b939-11ec-9acb-3939f0cc109a'; +import 'package:flutter/cupertino.dart'; +import 'package:fluttericon/font_awesome5_icons.dart'; +import 'package:fluttericon/font_awesome_icons.dart'; +import 'package:fluttericon/rpg_awesome_icons.dart'; +import 'package:unit2/model/login_data/user_info/role.dart'; + List levels = ['Establishments', 'Office']; List establishments = ['Provincial Government of Agusan del Norte']; List checkPointAreas = [ @@ -85,3 +90,17 @@ class Person extends ISuspensionBean { return lastname[0]; } } + +// List roles = [ +// Roles(name: 'QR scanner', icon: FontAwesome.qrcode), +// Roles(name: "Security", icon: FontAwesome5.user_shield), +// Roles(name: "Establishment point person", icon: FontAwesome.building_filled), +// Roles(name: "Registration in charge", icon: FontAwesome.user_plus), +// Roles(name: 'Super admin', icon: FontAwesome5.user_lock), +// Roles(name: "Purok president", icon: FontAwesome5.user_tie), +// Roles(name: "Check point inchage", icon: FontAwesome5.hand_paper), +// Roles(name: "Health officer", icon: RpgAwesome.health_decrease), + +// ]; + + diff --git a/unit2/lib/utils/app_router.dart b/unit2/lib/utils/app_router.dart new file mode 100644 index 0000000..cb7304f --- /dev/null +++ b/unit2/lib/utils/app_router.dart @@ -0,0 +1,14 @@ +// import 'package:flutter/cupertino.dart'; +// import 'package:flutter_bloc/flutter_bloc.dart'; + +// class AppRouter{ +// Route onGenerateRoute(RouteSettings routeSettings){ +// switch(routeSettings.name){ +// case '/': +// return BlocProvider( +// create: (context) => UserBloc()..add(GetApkVersion()), +// child: const UniT2Login(), +// ); +// } +// } +// } \ No newline at end of file diff --git a/unit2/lib/utils/global_context.dart b/unit2/lib/utils/global_context.dart new file mode 100644 index 0000000..6b7b74d --- /dev/null +++ b/unit2/lib/utils/global_context.dart @@ -0,0 +1,6 @@ +import 'package:flutter/material.dart'; + +class NavigationService { + static GlobalKey navigatorKey = + GlobalKey(); +} diff --git a/unit2/lib/utils/router.dart b/unit2/lib/utils/router.dart index 4d00ecb..d47138d 100644 --- a/unit2/lib/utils/router.dart +++ b/unit2/lib/utils/router.dart @@ -2,10 +2,12 @@ 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/screens/unit2/login/register.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'; @@ -21,24 +23,38 @@ final GoRouter goRouter = GoRouter(routes: [ path: '/', name: 'login', builder: (context, state) { - debugPrint("login bloc called"); - BlocProvider.of(context).add(GetApkVersion()); - return const UniT2Login(); + return BlocProvider( + create: (context) => UserBloc()..add(GetApkVersion()), + child: const UniT2Login(), + ); }, routes: [ - GoRoute( - name: 'register', - path: 'register', - builder: ((context, state) => const Register())), + // GoRoute( + // name: 'qr-login', + // path: 'qr-login', + // builder: ((context, state) => const QRLogin())), GoRoute( name: 'home', path: 'home', - builder: (context, state) => const DrawerScreen(), + builder: (context, state) { + UserData userData = state.extra as UserData; + return BlocProvider.value( + value: UserBloc()..add((LoadLoggedInUser(userData: userData))), + child: const DrawerScreen(), + ); + }, routes: [ GoRoute( name: 'profile', path: 'profile', - builder: (context, state) => const Profile(), + builder: (context, state) { + UserData userData = state.extra as UserData; + return BlocProvider.value( + value: UserBloc() + ..add((LoadLoggedInUser(userData: userData))), + child: const Profile(), + ); + }, routes: [ GoRoute( name: 'signature', diff --git a/unit2/lib/utils/text_container.dart b/unit2/lib/utils/text_container.dart index 9fe0563..8363228 100644 --- a/unit2/lib/utils/text_container.dart +++ b/unit2/lib/utils/text_container.dart @@ -14,7 +14,7 @@ const String login = "LOGIN"; const String sOSTitle = "Request SOS"; const String sOSReceivedMessage = "your SOS request has been received. Please wait for respondent's acknowledgement."; -const String unit2ModuleScreen = "uniT2 Modules"; +const String unit2ModuleScreen = "uniT Dashboard"; const String welcome = "Welcome to!"; const String unitApp = 'uniT-App'; const String loginToContinue = "Please login to continue."; diff --git a/unit2/lib/widgets/splash_screen.dart b/unit2/lib/widgets/splash_screen.dart index ceb6ba3..41a2a8d 100644 --- a/unit2/lib/widgets/splash_screen.dart +++ b/unit2/lib/widgets/splash_screen.dart @@ -12,36 +12,40 @@ class UniTSplashScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - SlideInUp( - from: 50, - duration: const Duration(milliseconds: 300), - child: SvgPicture.asset( - 'assets/svgs/logo.svg', - height: blockSizeVertical * 15.0, - allowDrawingOutsideViewBox: true, - color: primary, + return Container( + height: MediaQuery.of(context).size.height, + color: Colors.white, + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SlideInUp( + from: 50, + duration: const Duration(milliseconds: 300), + child: SvgPicture.asset( + 'assets/svgs/logo.svg', + height: blockSizeVertical * 12.0, + allowDrawingOutsideViewBox: true, + color: primary, + ), ), - ), - const SizedBox( - height: 24, - ), - SlideInDown( - from: 100, - duration: const Duration(milliseconds: 200), - child: Text("uniT-App", - style: TextStyle( - fontSize: blockSizeVertical * 5, - fontWeight: FontWeight.w800, - letterSpacing: .2, - height: 1, - color: Colors.black)), - ), - ], + const SizedBox( + height: 12, + ), + SlideInDown( + from: 100, + duration: const Duration(milliseconds: 200), + child: Text("uniT-App", + style: TextStyle( + fontSize: blockSizeVertical * 4, + fontWeight: FontWeight.w600, + letterSpacing: .2, + height: 1, + color: Colors.black)), + ), + ], + ), ), ); } diff --git a/unit2/pubspec.yaml b/unit2/pubspec.yaml index 7257490..fa8c45e 100644 --- a/unit2/pubspec.yaml +++ b/unit2/pubspec.yaml @@ -60,7 +60,7 @@ dependencies: signature: ^5.3.0 awesome_dialog: ^3.0.2 system_info2: ^2.0.4 - flutter_bloc: ^8.1.1 + flutter_bloc: ^8.0.0 equatable: ^2.0.5 dev_dependencies: