335 lines
14 KiB
Dart
335 lines
14 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:awesome_notifications/awesome_notifications.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'package:hub/backend/api_requests/api_calls.dart';
|
|
import 'package:hub/backend/notifications/firebase_messaging_service.dart';
|
|
import 'package:hub/components/atomic_components/shared_components_atoms/atom_image_svg_theme.dart';
|
|
import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart';
|
|
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
|
|
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
|
import 'package:hub/flutter_flow/flutter_flow_widgets.dart';
|
|
import 'package:hub/flutter_flow/nav/nav.dart';
|
|
import 'package:hub/pages/reception_page/reception_page_model.dart';
|
|
import 'package:hub/shared/utils/dialog_util.dart';
|
|
import 'package:hub/shared/utils/storage_util.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class ReceptionPageWidget extends StatefulWidget {
|
|
const ReceptionPageWidget({super.key});
|
|
|
|
@override
|
|
State<ReceptionPageWidget> createState() => _ReceptionPageWidgetState();
|
|
}
|
|
|
|
class _ReceptionPageWidgetState extends State<ReceptionPageWidget>
|
|
with WidgetsBindingObserver {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addObserver(this);
|
|
() async {
|
|
final lifecycle = await AwesomeNotifications().getAppLifeCycle();
|
|
log('lifecycle: $lifecycle');
|
|
}();
|
|
|
|
FirebaseMessagingService().updateDeviceToken();
|
|
|
|
processLocals();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
WidgetsBinding.instance
|
|
.removeObserver(this); // Remove a classe como observador
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> processLocals() async {
|
|
try {
|
|
final GetLocalsCall callback = PhpGroup.getLocalsCall;
|
|
|
|
var response = await callback.call();
|
|
|
|
if (response.jsonBody['error'] == false) {
|
|
List<dynamic> locals = response.jsonBody['locais'] ?? [];
|
|
|
|
if (locals.isNotEmpty) {
|
|
StorageUtil().haveLocal = true;
|
|
StorageUtil().isLogged = true;
|
|
await WidgetsBinding.instance.endOfFrame;
|
|
dispose();
|
|
StorageUtil().context?.go('/homePage');
|
|
await showModalSelectLocal();
|
|
}
|
|
}
|
|
} catch (e, s) {
|
|
log(e.toString(), stackTrace: s);
|
|
}
|
|
}
|
|
|
|
Future<void> processData() async {
|
|
try {
|
|
final GetDadosCall callback = PhpGroup.getDadosCall;
|
|
|
|
var response = await callback.call();
|
|
|
|
final error = response.jsonBody['error'];
|
|
// final errorMsg = response.jsonBody['error_msg'];
|
|
|
|
if (error == false) {
|
|
final bool whatsapp = response.jsonBody['whatsapp'] ?? false;
|
|
final bool provisional = response.jsonBody['provisional'] ?? false;
|
|
final bool pets = response.jsonBody['pet'] ?? false;
|
|
final String petAmountRegister =
|
|
response.jsonBody['petAmountRegister'].toString().isEmpty
|
|
? '0'
|
|
: response.jsonBody['petAmountRegister'].toString();
|
|
final String name = response.jsonBody['visitado']['VDO_NOME'];
|
|
|
|
StorageUtil().whatsapp = whatsapp;
|
|
StorageUtil().provisional = provisional;
|
|
StorageUtil().pets = pets;
|
|
StorageUtil().petAmountRegister = petAmountRegister;
|
|
StorageUtil().userName = name;
|
|
|
|
safeSetState(() {});
|
|
return;
|
|
} else if (error == true) {
|
|
final BuildContext? context = StorageUtil().context;
|
|
if (context != null) {
|
|
DialogUtil.warningDefault(context)
|
|
.whenComplete(() => processLocals());
|
|
}
|
|
safeSetState(() {});
|
|
}
|
|
|
|
return;
|
|
} catch (e) {
|
|
log('() => error: $e');
|
|
final BuildContext? context = StorageUtil().context;
|
|
if (context != null) {
|
|
DialogUtil.warningDefault(context).whenComplete(() => processLocals());
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> showModalSelectLocal() async {
|
|
StorageUtil().context?.go('/homePage');
|
|
await showModalBottomSheet(
|
|
isScrollControlled: true,
|
|
backgroundColor: Colors.transparent,
|
|
enableDrag: false,
|
|
isDismissible: false,
|
|
context: context,
|
|
builder: (context) => Padding(
|
|
padding: MediaQuery.viewInsetsOf(context),
|
|
child: const BottomArrowLinkedLocalsComponentWidget(),
|
|
),
|
|
).then((_) async {
|
|
StorageUtil().haveLocal = true;
|
|
await processData();
|
|
});
|
|
}
|
|
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
if (state == AppLifecycleState.resumed) {
|
|
setState(() {
|
|
processLocals();
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
StorageUtil().context = context;
|
|
return ChangeNotifierProvider(
|
|
create: (context) => ReceptionPageModel(),
|
|
child: Scaffold(
|
|
body: Consumer<ReceptionPageModel>(
|
|
builder: (context, ReceptionPageModel model, child) {
|
|
return SafeArea(
|
|
child: Center(
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.max,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(45, 0, 45, 15.0),
|
|
child: Text(
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText:
|
|
'Falta pouco para você utilizar o FRE Access Hub...',
|
|
enText:
|
|
'You are close to using the FRE Access Hub...'),
|
|
textAlign: TextAlign.center,
|
|
style: FlutterFlowTheme.of(context)
|
|
.displayLarge
|
|
.override(
|
|
fontFamily: 'Plus Jakarta Sans',
|
|
color: FlutterFlowTheme.of(context).accent1,
|
|
fontSize: 20.0,
|
|
letterSpacing: 0.0,
|
|
fontWeight: FontWeight.w700,
|
|
useGoogleFonts: GoogleFonts.asMap()
|
|
.containsKey('Plus Jakarta Sans'),
|
|
),
|
|
),
|
|
),
|
|
const AtomImageSvgTheme(
|
|
filename: 'reception', width: 180, height: 180),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(70, 30, 70.0, 60),
|
|
child: Text(
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText:
|
|
'Envie seu identificador para seu condomínio para vincularem sua conta aos nossos sistemas.',
|
|
enText:
|
|
'Send your identifier to your condominium to link your account to our systems.'),
|
|
textAlign: TextAlign.center,
|
|
style: FlutterFlowTheme.of(context)
|
|
.displaySmall
|
|
.override(
|
|
fontFamily: 'Nunito Sans',
|
|
color: FlutterFlowTheme.of(context).primaryText,
|
|
fontSize: 14.0,
|
|
letterSpacing: 0.0,
|
|
fontWeight: FontWeight.w600,
|
|
useGoogleFonts: GoogleFonts.asMap()
|
|
.containsKey('Plus Jakarta Sans'),
|
|
),
|
|
),
|
|
),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.max,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(60, 0, 60, 10),
|
|
child: Tooltip(
|
|
message: FFLocalizations.of(context).getVariableText(
|
|
ptText:
|
|
'Seu identificador é utilizado para efetuar\no vínculo do seu APP com o condominio.',
|
|
enText: 'My Identifier'),
|
|
textStyle: FlutterFlowTheme.of(context)
|
|
.labelSmall
|
|
.override(
|
|
fontFamily: 'Nunito Sans',
|
|
color: FlutterFlowTheme.of(context)
|
|
.secondaryText,
|
|
fontSize: 10.0,
|
|
letterSpacing: 0.0,
|
|
fontWeight: FontWeight.w500,
|
|
useGoogleFonts: GoogleFonts.asMap()
|
|
.containsKey('Plus Jakarta Sans'),
|
|
),
|
|
child: FFButtonWidget(
|
|
onPressed: () => model.getIdenfifier(context),
|
|
text: FFLocalizations.of(context)
|
|
.getVariableText(
|
|
ptText: 'Meu Identificador',
|
|
enText: 'My Identifier'),
|
|
options: FFButtonOptions(
|
|
width: double.infinity,
|
|
height: 44.0,
|
|
padding: const EdgeInsetsDirectional.fromSTEB(
|
|
0.0, 0.0, 0.0, 0.0),
|
|
iconPadding:
|
|
const EdgeInsetsDirectional.fromSTEB(
|
|
0.0, 0.0, 0.0, 0.0),
|
|
color: FlutterFlowTheme.of(context).primary,
|
|
textStyle: FlutterFlowTheme.of(context)
|
|
.titleSmall
|
|
.override(
|
|
fontFamily: 'Nunito Sans',
|
|
color:
|
|
FlutterFlowTheme.of(context).info,
|
|
fontSize: 14.0,
|
|
letterSpacing: 0.0,
|
|
fontWeight: FontWeight.w500,
|
|
useGoogleFonts: GoogleFonts.asMap()
|
|
.containsKey('Plus Jakarta Sans'),
|
|
),
|
|
elevation: 3.0,
|
|
borderSide: const BorderSide(
|
|
color: Colors.transparent,
|
|
width: 1.0,
|
|
),
|
|
borderRadius: BorderRadius.circular(12.0),
|
|
),
|
|
showLoadingIndicator: false,
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(60, 0, 60, 0),
|
|
child: FFButtonWidget(
|
|
onPressed: () async {
|
|
PhpGroup.unregisterDevice();
|
|
|
|
StorageUtil.purge();
|
|
setState(() {});
|
|
|
|
context.go(
|
|
'/welcomePage',
|
|
extra: <String, dynamic>{
|
|
kTransitionInfoKey: const TransitionInfo(
|
|
hasTransition: true,
|
|
transitionType: PageTransitionType.scale,
|
|
alignment: Alignment.bottomCenter,
|
|
),
|
|
},
|
|
);
|
|
},
|
|
text: FFLocalizations.of(context).getVariableText(
|
|
ptText: 'Sair da Conta', enText: 'Logout'),
|
|
options: FFButtonOptions(
|
|
width: double.infinity,
|
|
height: 44.0,
|
|
padding: const EdgeInsetsDirectional.fromSTEB(
|
|
0.0, 0.0, 0.0, 0.0),
|
|
iconPadding:
|
|
const EdgeInsetsDirectional.fromSTEB(
|
|
0.0, 0.0, 0.0, 0.0),
|
|
color:
|
|
FlutterFlowTheme.of(context).customColor1,
|
|
textStyle: FlutterFlowTheme.of(context)
|
|
.titleSmall
|
|
.override(
|
|
fontFamily: 'Nunito Sans',
|
|
color: FlutterFlowTheme.of(context)
|
|
.primaryBackground,
|
|
fontSize: 14.0,
|
|
letterSpacing: 0.0,
|
|
fontWeight: FontWeight.w500,
|
|
useGoogleFonts: GoogleFonts.asMap()
|
|
.containsKey('Plus Jakarta Sans'),
|
|
),
|
|
elevation: 3.0,
|
|
borderSide: const BorderSide(
|
|
color: Colors.transparent,
|
|
width: 1.0,
|
|
),
|
|
borderRadius: BorderRadius.circular(12.0),
|
|
),
|
|
showLoadingIndicator: false,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|