convert swtich offline into bloc

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
unknown 2023-10-06 20:19:06 +08:00
parent f9fd714fa6
commit ebb04ad358
15 changed files with 245 additions and 135 deletions

View File

@ -0,0 +1,28 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/utils/global.dart';
import '../../../model/offline/offlane_modules.dart';
import '../../../model/offline/offline_profile.dart';
part 'offline_event.dart';
part 'offline_state.dart';
class OfflineBloc extends Bloc<OfflineEvent, OfflineState> {
OfflineBloc() : super(OfflineInitial()) {
on<SwitchOffline>((event, emit) async {
try {
List<dynamic> modules = await OFFLINE!.get('modules');
List<OfflineModules> offlineModules = [];
for (var module in modules) {
offlineModules.add(module);
}
OfflineProfile offlineProfile = await OFFLINE!.get('offline_profile');
emit(OfflineModeState(
offlineModules: offlineModules, offlineProfile: offlineProfile));
} catch (e) {
emit(OfflineErrorState(message: e.toString()));
}
});
}
}

View File

@ -0,0 +1,13 @@
part of 'offline_bloc.dart';
class OfflineEvent extends Equatable {
const OfflineEvent();
@override
List<Object> get props => [];
}
class SwitchOffline extends OfflineEvent {
@override
List<Object> get props => [];
}

View File

@ -0,0 +1,26 @@
part of 'offline_bloc.dart';
class OfflineState extends Equatable {
const OfflineState();
@override
List<Object> get props => [];
}
class OfflineInitial extends OfflineState {}
class OfflineModeState extends OfflineState {
final OfflineProfile offlineProfile;
final List<OfflineModules> offlineModules;
const OfflineModeState(
{required this.offlineModules, required this.offlineProfile});
@override
List<Object> get props => [offlineProfile, offlineModules];
}
class OfflineLoadingState extends OfflineState {}
class OfflineErrorState extends OfflineState {
final String message;
const OfflineErrorState({required this.message});
}

View File

@ -10,7 +10,7 @@ class GetApkVersion extends UserEvent {
final String password;
GetApkVersion({required this.password, required this.username});
@override
List<Object> get props => [username,password];
List<Object> get props => [username, password];
}
class UserLogin extends UserEvent {
@ -28,15 +28,15 @@ class LoadLoggedInUser extends UserEvent {
class GetUuid extends UserEvent {
GetUuid();
}
class LoadUuid extends UserEvent{
class LoadUuid extends UserEvent {
LoadUuid();
}
class LoadVersion extends UserEvent {
final String? username;
final String? password;
LoadVersion({this.password,this.username});
LoadVersion({this.password, this.username});
}
class UuidLogin extends UserEvent {

View File

@ -1,7 +1,6 @@
part of 'user_bloc.dart';
abstract class UserState extends Equatable {
@override
List<Object> get props => [];
}
@ -20,7 +19,6 @@ class UserLoading extends UserState {
}
class SplashScreen extends UserState {
@override
List<Object> get props => [];
}
@ -31,13 +29,19 @@ class UserError extends UserState {
@override
List<Object> get props => [];
}
class UserLoggedIn extends UserState{
class UserLoggedIn extends UserState {
final List<AssignedArea>? estPersonAssignedArea;
final UserData? userData;
final String? message;
final bool? success;
final bool? savedCredentials;
UserLoggedIn({this.userData,this.message,this.success,this.savedCredentials, required this.estPersonAssignedArea});
UserLoggedIn(
{this.userData,
this.message,
this.success,
this.savedCredentials,
required this.estPersonAssignedArea});
}
class VersionLoaded extends UserState {
@ -45,33 +49,34 @@ class VersionLoaded extends UserState {
final String? apkVersion;
final String? username;
final String? password;
VersionLoaded({this.versionInfo,this.apkVersion, this.password,this.username});
VersionLoaded(
{this.versionInfo, this.apkVersion, this.password, this.username});
@override
List<Object> get props => [versionInfo!];
}
class UuidLoaded extends UserState{
class UuidLoaded extends UserState {
final String uuid;
UuidLoaded({required this.uuid});
@override
List<Object> get props => [uuid];
}
class InternetTimeout extends UserState{
class InternetTimeout extends UserState {
final String message;
InternetTimeout({required this.message});
@override
List<Object> get props => [message];
}
class InvalidCredentials extends UserState{
final String message ;
InvalidCredentials ({required this.message});
class InvalidCredentials extends UserState {
final String message;
InvalidCredentials({required this.message});
}
class LoginErrorState extends UserState{
class LoginErrorState extends UserState {
final String message;
LoginErrorState({required this.message});
}
class ErrorWithOfflineMode extends UserState{
}
class ErrorWithOfflineMode extends UserState {}

View File

@ -9,18 +9,18 @@ import '../../../../bloc/user/user_bloc.dart';
import '../../../../widgets/splash_screen.dart';
class OfflineDrawerScreen extends StatefulWidget {
final List<OfflineModules> modules;
const OfflineDrawerScreen({Key? key ,required this.modules}) : super(key: key,);
const OfflineDrawerScreen({
Key? key,
}) : super(
key: key,
);
@override
State<OfflineDrawerScreen> createState() => _OfflineDrawerScreenState();
}
class _OfflineDrawerScreenState extends State<OfflineDrawerScreen> {
final zoomDrawerController = ZoomDrawerController();
@override
@override
Widget build(BuildContext context) {
return ZoomDrawer(
@ -28,7 +28,7 @@ class _OfflineDrawerScreenState extends State<OfflineDrawerScreen> {
menuScreen: const OfflineMenuScreen(),
mainScreen: SizedBox(
height: MediaQuery.of(context).size.height,
child: OfflineModuleScreen(modules: widget.modules,)),
child: const OfflineModuleScreen()),
style: DrawerStyle.defaultStyle,
borderRadius: 24.0,
showShadow: false,
@ -39,5 +39,4 @@ class _OfflineDrawerScreenState extends State<OfflineDrawerScreen> {
menuBackgroundColor: Colors.grey,
);
}
}

View File

@ -1,14 +1,15 @@
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:unit2/bloc/offline/offline_bloc/offline_bloc.dart';
import 'package:unit2/model/offline/offlane_modules.dart';
import 'package:unit2/screens/passo/passo_dashboard.dart';
import 'package:unit2/screens/unit2/homepage.dart/components/dashboard/shared_card_label.dart';
import 'package:unit2/theme-data.dart/colors.dart';
class OfflineModuleScreen extends StatelessWidget {
final List<OfflineModules> modules;
const OfflineModuleScreen({super.key, required this.modules});
const OfflineModuleScreen({super.key});
@override
Widget build(BuildContext context) {
@ -27,7 +28,13 @@ class OfflineModuleScreen extends StatelessWidget {
),
),
),
body: Padding(
body: BlocConsumer<OfflineBloc, OfflineState>(
listener: (context, state) {
// TODO: implement listener
},
builder: (context, state) {
if (state is OfflineModeState) {
return Padding(
padding: const EdgeInsets.all(24),
child: GridView.count(
shrinkWrap: true,
@ -35,17 +42,23 @@ class OfflineModuleScreen extends StatelessWidget {
crossAxisSpacing: 8,
mainAxisSpacing: 10,
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 5),
children: modules
padding:
const EdgeInsets.symmetric(vertical: 5, horizontal: 5),
children: state.offlineModules
.map((e) => CardLabel(
icon: FontAwesome5.eye,
title: "Field Surveyor",
ontap: () {
Navigator.push(context, MaterialPageRoute(builder: ((context) {
Navigator.push(context,
MaterialPageRoute(builder: ((context) {
return PassoDashBoard();
})));
}))
.toList()),
);
}
return Container();
},
));
}
}

View File

@ -44,7 +44,6 @@ import '../../bloc/profile/voluntary_works/voluntary_work_bloc.dart';
import '../../bloc/profile/workHistory/workHistory_bloc.dart';
import '../../bloc/user/user_bloc.dart';
import '../../model/profile/basic_information/primary-information.dart';
import '../unit2/homepage.dart/components/menu.dart';
import 'components/main_menu.dart';
import 'components/submenu.dart';
@ -62,10 +61,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
String? token;
Profile profile;
return WillPopScope(
onWillPop: () async{
setState(() {
});
onWillPop: () async {
setState(() {});
return true;
},
child: Scaffold(
@ -83,7 +80,6 @@ class _ProfileInfoState extends State<ProfileInfo> {
profileId = state.userData!.user!.login!.user!.profileId;
token = state.userData!.user!.login!.token!;
if (globalCurrentProfile == null) {
profile = state.userData!.employeeInfo!.profile!;
globalCurrentProfile = profile;
} else {
@ -120,7 +116,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
ExpandableGroup(
collapsedIcon:
const Icon(Icons.keyboard_arrow_down),
expandedIcon: const Icon(Icons.keyboard_arrow_up),
expandedIcon:
const Icon(Icons.keyboard_arrow_up),
header: const ListTile(
leading: Icon(
Elusive.address_book,
@ -128,7 +125,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
),
title: Text(
"Basic Information",
style: TextStyle(fontWeight: FontWeight.bold),
style:
TextStyle(fontWeight: FontWeight.bold),
),
),
items: [
@ -138,7 +136,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
return BlocProvider<ProfileBloc>.value(
value: ProfileBloc()
..add(GetPrimaryBasicInfo(
primaryBasicInformation: profile)),
primaryBasicInformation:
profile)),
child: PrimaryInfo(
token: token!,
profileId: profileId!,
@ -152,8 +151,10 @@ class _ProfileInfoState extends State<ProfileInfo> {
return BlocProvider(
create: (context) => AddressBloc()
..add(GetAddress(
addresses: state.profileInformation
.basicInfo.addresses)),
addresses: state
.profileInformation
.basicInfo
.addresses)),
child: const AddressScreen(),
);
}));
@ -163,9 +164,11 @@ class _ProfileInfoState extends State<ProfileInfo> {
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) {
return BlocProvider(
create: (context) => IdentificationBloc()
create: (context) =>
IdentificationBloc()
..add(GetIdentifications(
identificationInformation: state
identificationInformation:
state
.profileInformation
.basicInfo
.identifications)),
@ -203,7 +206,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
.profileInformation
.basicInfo
.citizenships,
profileId: profileId!, token: token!),
profileId: profileId!,
token: token!),
);
}));
}),
@ -218,7 +222,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
return BlocProvider(
create: (context) => FamilyBloc()
..add(GetFamilies(
profileId: profileId!, token: token!)),
profileId: profileId!,
token: token!)),
child: const FamilyBackgroundScreen(),
);
}));
@ -234,7 +239,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
return BlocProvider(
create: (context) => EducationBloc()
..add(GetEducationalBackground(
profileId: profileId!, token: token!)),
profileId: profileId!,
token: token!)),
child: const EducationScreen(),
);
}));
@ -250,7 +256,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
return BlocProvider(
create: (context) => EligibilityBloc()
..add(GetEligibilities(
profileId: profileId!, token: token!)),
profileId: profileId!,
token: token!)),
child: const EligibiltyScreen(),
);
}));
@ -266,7 +273,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
return BlocProvider(
create: (context) => WorkHistoryBloc()
..add(GetWorkHistories(
profileId: profileId!, token: token!)),
profileId: profileId!,
token: token!)),
child: const WorkHistoryScreen(),
);
}));
@ -282,7 +290,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
return BlocProvider(
create: (context) => VoluntaryWorkBloc()
..add(GetVoluntarWorks(
profileId: profileId!, token: token!)),
profileId: profileId!,
token: token!)),
child: const VolunataryWorkScreen(),
);
}));
@ -296,9 +305,11 @@ class _ProfileInfoState extends State<ProfileInfo> {
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) {
return BlocProvider(
create: (context) => LearningDevelopmentBloc()
create: (context) =>
LearningDevelopmentBloc()
..add(GetLearningDevelopments(
profileId: profileId!, token: token!)),
profileId: profileId!,
token: token!)),
child: const LearningAndDevelopmentScreen(),
);
}));
@ -314,7 +325,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
return BlocProvider(
create: (context) => ReferencesBloc()
..add(GetReferences(
profileId: profileId!, token: token!)),
profileId: profileId!,
token: token!)),
child: const ReferencesScreen(),
);
}));
@ -323,7 +335,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
ExpandableGroup(
collapsedIcon:
const Icon(Icons.keyboard_arrow_down),
expandedIcon: const Icon(Icons.keyboard_arrow_up),
expandedIcon:
const Icon(Icons.keyboard_arrow_up),
header: const ListTile(
leading: Icon(
Icons.info,
@ -331,7 +344,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
),
title: Text(
"Other Information",
style: TextStyle(fontWeight: FontWeight.bold),
style:
TextStyle(fontWeight: FontWeight.bold),
),
),
items: [
@ -382,7 +396,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
ExpandableGroup(
collapsedIcon:
const Icon(Icons.keyboard_arrow_down),
expandedIcon: const Icon(Icons.keyboard_arrow_up),
expandedIcon:
const Icon(Icons.keyboard_arrow_up),
header: const ListTile(
leading: Icon(
FontAwesome5.laptop_house,
@ -390,7 +405,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
),
title: Text(
"Assets",
style: TextStyle(fontWeight: FontWeight.bold),
style:
TextStyle(fontWeight: FontWeight.bold),
),
),
items: [

View File

@ -137,10 +137,10 @@ class BuildInformation extends StatelessWidget {
@override
Widget build(BuildContext context) {
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
globalFistname =
globalFistname ?? userData.employeeInfo!.profile!.firstName!.toUpperCase();
globalLastname =
globalLastname ?? userData.employeeInfo!.profile!.lastName!.toUpperCase();
globalFistname = globalFistname ??
userData.employeeInfo!.profile!.firstName!.toUpperCase();
globalLastname = globalLastname ??
userData.employeeInfo!.profile!.lastName!.toUpperCase();
globalMiddleName = globalMiddleName ??
(userData.employeeInfo == null
? ''
@ -182,7 +182,7 @@ class BuildInformation extends StatelessWidget {
return QRFullScreenImage(uuid: uuid);
}));
},
child: QrImageView(
child: QrImage(
data: uuid!,
size: blockSizeVertical * 24,
),

View File

@ -12,12 +12,12 @@ class QRFullScreenImage extends StatelessWidget {
return Scaffold(
appBar: AppBar(
centerTitle: true,
backgroundColor: primary,title: const Text("Profile QR Code"),),
body: Center(
child: QrImageView(
data: uuid,
size: blockSizeVertical * 50
backgroundColor: primary,
title: const Text("Profile QR Code"),
),
),);
body: Center(
child: QrImage(data: uuid, size: blockSizeVertical * 50),
),
);
}
}

View File

@ -1,14 +1,16 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:unit2/bloc/offline/offline_bloc/offline_bloc.dart';
import 'package:unit2/model/offline/offlane_modules.dart';
import 'package:unit2/screens/offline/homepage/drawer.dart';
import 'package:unit2/screens/offline/homepage/menu_screen.dart';
import 'package:unit2/screens/unit2/homepage.dart/components/drawer-screen.dart';
import 'package:unit2/screens/unit2/homepage.dart/components/menu_tile.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:fluttericon/web_symbols_icons.dart';
import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:unit2/utils/global_context.dart';
import '../../../../model/login_data/user_info/user_data.dart';
import 'menu.dart';
import '../../../../utils/global.dart';
class MenuScreen extends StatefulWidget {
@ -72,11 +74,17 @@ class _MenuScreenState extends State<MenuScreen> {
style: TextStyle(color: Colors.black),
),
onTap: () async {
List<OfflineModules> modules = await OFFLINE!.get('modules');
Navigator.pushReplacement(NavigationService.navigatorKey.currentState!.context,
Navigator.pushReplacement(
NavigationService
.navigatorKey.currentState!.context,
MaterialPageRoute(builder: ((context) {
return OfflineDrawerScreen(modules: modules,);
return BlocProvider(
create: (context) =>
OfflineBloc()..add(SwitchOffline()),
child: const OfflineDrawerScreen(),
);
})));
;
},
)
: Container())

View File

@ -7,6 +7,7 @@ import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:unit2/bloc/offline/offline_bloc/offline_bloc.dart';
import 'package:unit2/model/offline/offlane_modules.dart';
import 'package:unit2/screens/offline/homepage/drawer.dart';
import 'package:unit2/screens/unit2/login/components/update_required.dart';
@ -402,15 +403,17 @@ class _UniT2LoginState extends State<UniT2Login> {
height: 50,
child: ElevatedButton.icon(
icon: const Icon(Icons.signal_cellular_alt),
style: mainBtnStyle(second, Colors.transparent, primary),
style:
mainBtnStyle(second, Colors.transparent, primary),
onPressed: () async {
List<OfflineModules> offlinemodules = await OFFLINE!.get('modules');
Navigator.pushReplacement(
NavigationService
.navigatorKey.currentState!.context,
MaterialPageRoute(builder: ((context) {
return OfflineDrawerScreen(
modules: offlinemodules,
return BlocProvider(
create: (context) =>
OfflineBloc()..add(SwitchOffline()),
child: const OfflineDrawerScreen(),
);
})));
},

View File

@ -1,15 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:unit2/bloc/passo/bulding/property_info/property_info_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/role/pass_check/pass_check_bloc.dart';
import 'package:unit2/bloc/sos/sos_bloc.dart';
import 'package:unit2/model/passo/property_info.dart';
import 'package:unit2/screens/passo/passo_dashboard.dart';
import 'package:unit2/screens/passo/building_home.dart';
import 'package:unit2/screens/sos/index.dart';
import 'package:unit2/screens/unit2/homepage.dart/components/dashboard/dashboard.dart';
import 'package:unit2/screens/unit2/homepage.dart/components/menu.dart';
import 'package:unit2/screens/unit2/login/login.dart';
import 'package:unit2/screens/unit2/roles/rbac/rbac.dart';
import 'package:unit2/utils/global_context.dart';
@ -18,6 +14,7 @@ import '../bloc/user/user_bloc.dart';
import '../screens/profile/profile.dart';
import '../screens/unit2/basic-info/basic-info.dart';
import '../screens/unit2/homepage.dart/components/drawer-screen.dart';
import '../screens/unit2/homepage.dart/components/menu_tile.dart';
import '../screens/unit2/login/qr_login.dart';
import '../screens/unit2/roles/qr_code_scanner.dart/settings_screen.dart';

View File

@ -5,8 +5,8 @@ class Url {
String host() {
// return '192.168.10.183:3000';
return 'agusandelnorte.gov.ph';
// return "192.168.10.219:3000";
// return 'agusandelnorte.gov.ph';
return "192.168.10.219:3000";
// return "192.168.10.241";
// return "192.168.10.221:3004";
// return "playweb.agusandelnorte.gov.ph";
@ -311,7 +311,8 @@ class Url {
String getRoleAssignment() {
return "/api/account/auth/role_assignment/";
}
String getPermissionAssignment(){
String getPermissionAssignment() {
return "/api/account/auth/permission_assignment/";
}
@ -347,7 +348,8 @@ class Url {
String getBarangays() {
return "/api/web_app/location/barangay/";
}
String getPurok(){
String getPurok() {
return "/api/web_app/location/purok/";
}