with go router navigation

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
rodolfobacuinjr 2023-01-23 11:02:59 +08:00
parent 0c0c6c1c90
commit c088dbc2a2
20 changed files with 745 additions and 427 deletions

View File

@ -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<UserEvent, UserState> {
UserData? _userData;
UserBloc() : super(UserInitial()) {
// this event is called when opening the app to check if
// there is new app version
on<GetApkVersion>((event, emit) async {
debugPrint("getApkEvent is called");
try {
emit(SplashScreen());
VersionInfo versionInfo = await AuthService.instance.getVersionInfo();
@ -24,14 +27,25 @@ class UserBloc extends Bloc<UserEvent, UserState> {
message: e.toString(),
));
}
});
on<UserLogin>((event, emit) async {
try {
UserData? userData = await AuthService.instance.webLogin(username: event.username,password: event.password);
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<LoadLoggedInUser>((event, emit) {
emit(UserLoggedIn(userData: event.userData));
});
on<GetUuid>((event, emit) async {
ScanResult result = await QRCodeBarCodeScanner.instance.scanner();
if(result.rawContent.toString().isNotEmpty){
emit(UuidLoaded(uuid: result.rawContent.toString()));
}
});
}
}

View File

@ -1,13 +1,12 @@
part of 'user_bloc.dart';
abstract class UserEvent extends Equatable {
const UserEvent();
@override
List<Object> get props => [];
}
class GetApkVersion extends UserEvent{
GetApkVersion();
@override
List<Object> 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();
}

View File

@ -1,17 +1,20 @@
part of 'user_bloc.dart';
abstract class UserState extends Equatable {
const UserState();
@override
List<Object> get props => [];
}
class UserInitial extends UserState {}
class UserInitial extends UserState {
UserInitial();
@override
List<Object> get props => [];
}
class UserLoading extends UserState {
final String? message;
const UserLoading({this.message});
UserLoading({this.message});
@override
List<Object> 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<Object> 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<Object> get props => [versionInfo!];
}
class UuidLoaded extends UserState{
final String uuid;
UuidLoaded({required this.uuid});
@override
List<Object> get props => [uuid];
}

View File

@ -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;
@ -37,9 +40,14 @@ class MyApp extends StatelessWidget {
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,

View File

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

View File

@ -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,10 +18,16 @@ class _DrawerScreenState extends State<DrawerScreen> {
final zoomDrawerController = ZoomDrawerController();
@override
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: const MenuScreen(),
mainScreen: const MainScreen(),
menuScreen: MenuScreen(userData: state.userData,),
mainScreen: SizedBox(
height: MediaQuery.of(context).size.height,
child: const MainScreen()),
style: DrawerStyle.defaultStyle,
borderRadius: 24.0,
showShadow: false,
@ -28,5 +37,10 @@ class _DrawerScreenState extends State<DrawerScreen> {
closeCurve: Curves.easeOut,
menuBackgroundColor: Colors.grey,
);
}
return const UniTSplashScreen();
},
);
}
}

View File

@ -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<MenuScreen> createState() => _MenuScreenState();
@ -16,6 +18,10 @@ class MenuScreen extends StatefulWidget {
class _MenuScreenState extends State<MenuScreen> {
@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<MenuScreen> {
child: Column(
// ignore: prefer_const_literals_to_create_immutables
children: <Widget>[
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<MenuScreen> {
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!),
)),
],
),

View File

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

View File

@ -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,14 +21,34 @@ class MainScreen extends StatefulWidget {
}
class _MainScreenState extends State<MainScreen> {
bool hasModule = false;
List<Module> 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: BlocBuilder<UserBloc, UserState>(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,
@ -42,12 +70,49 @@ class _MainScreenState extends State<MainScreen> {
),
),
),
body: hasModule
? const Center(
child: Text('Main Screen'),
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> roles;
Module({required this.name, required this.roles});
}
class Roles {
final IconData icon;
final Role role;
Roles({required this.role, required this.icon});
}

View File

@ -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<UniT2Login> {
body: ProgressHUD(
child: BlocConsumer<UserBloc, UserState>(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<UniT2Login> {
return SizedBox(
child: SingleChildScrollView(
child: Stack(
alignment: Alignment.center,
children: [
Positioned(
bottom: 0,
@ -64,11 +75,11 @@ class _UniT2LoginState extends State<UniT2Login> {
const EdgeInsets.symmetric(horizontal: 25),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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<UniT2Login> {
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<UniT2Login> {
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<UserBloc>(context)
// .add(QRCodelogin());
onPressed: () {
context
.read<UserBloc>()
.add(GetUuid());
},
),
)),
@ -302,9 +306,7 @@ class _UniT2LoginState extends State<UniT2Login> {
if (state is SplashScreen) {
return const UniTSplashScreen();
}
return const Center(
child: Text("Default"),
);
return Container();
}),
),
),

View File

@ -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<QRLogin> createState() => _QRLoginState();
}
class _QRLoginState extends State<QRLogin> {
bool showSuffixIcon = false;
bool _showPassword = true;
final _formKey = GlobalKey<FormBuilderState>();
@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<UserBloc, UserState>(
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<UserBloc>(context)
.add(UserLogin(
username: _formKey
.currentState!.value['username'],
password: _formKey
.currentState!.value['password'],
));
}
},
child: const Text(submit)),
)
],
),
),
),
],
),
);
},
),
),
);
}
}

View File

@ -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<Register> createState() => _RegisterState();
}
class _RegisterState extends State<Register> {
bool showSuffixIcon = false;
bool _showPassword = true;
final _formKey = GlobalKey<FormBuilderState>();
@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)),
)
],
),
),
),
],
),
),
),
);
}
}

View File

@ -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,7 +25,12 @@ class Profile extends StatelessWidget {
onWillPop: () async {
return Future.value(true);
},
child: SafeArea(
child: ProgressHUD(
child: BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
state.userData!.employeeInfo!.profile!.sex!.toUpperCase();
return SafeArea(
child: Scaffold(
body: SizedBox(
width: screenWidth,
@ -55,7 +65,7 @@ class Profile extends StatelessWidget {
left: 20,
child: IconButton(
onPressed: () {
context.go(context.namedLocation('home'));
Navigator.pop(context);
},
icon: const Icon(
FontAwesome5.arrow_left,
@ -79,20 +89,37 @@ class Profile extends StatelessWidget {
SizedBox(
height: blockSizeVertical * 5,
),
const BuildInformation(),
BuildInformation(
userData: state.userData!,
),
],
),
),
),
);
}
return const UniTSplashScreen();
},
),
),
);
}
}
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(

View File

@ -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<String> levels = ['Establishments', 'Office'];
List<String> establishments = ['Provincial Government of Agusan del Norte'];
List<String> checkPointAreas = [
@ -85,3 +90,17 @@ class Person extends ISuspensionBean {
return lastname[0];
}
}
// List<Roles> 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),
// ];

View File

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

View File

@ -0,0 +1,6 @@
import 'package:flutter/material.dart';
class NavigationService {
static GlobalKey<NavigatorState> navigatorKey =
GlobalKey<NavigatorState>();
}

View File

@ -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: <GoRoute>[
path: '/',
name: 'login',
builder: (context, state) {
debugPrint("login bloc called");
BlocProvider.of<UserBloc>(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<UserBloc>.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<UserBloc>.value(
value: UserBloc()
..add((LoadLoggedInUser(userData: userData))),
child: const Profile(),
);
},
routes: [
GoRoute(
name: 'signature',

View File

@ -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.";

View File

@ -12,7 +12,10 @@ class UniTSplashScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
return Container(
height: MediaQuery.of(context).size.height,
color: Colors.white,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
@ -22,27 +25,28 @@ class UniTSplashScreen extends StatelessWidget {
duration: const Duration(milliseconds: 300),
child: SvgPicture.asset(
'assets/svgs/logo.svg',
height: blockSizeVertical * 15.0,
height: blockSizeVertical * 12.0,
allowDrawingOutsideViewBox: true,
color: primary,
),
),
const SizedBox(
height: 24,
height: 12,
),
SlideInDown(
from: 100,
duration: const Duration(milliseconds: 200),
child: Text("uniT-App",
style: TextStyle(
fontSize: blockSizeVertical * 5,
fontWeight: FontWeight.w800,
fontSize: blockSizeVertical * 4,
fontWeight: FontWeight.w600,
letterSpacing: .2,
height: 1,
color: Colors.black)),
),
],
),
),
);
}
}

View File

@ -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: