258 lines
8.2 KiB
Dart
258 lines
8.2 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/gestures.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/backend/schema/enums/enums.dart';
|
|
import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart';
|
|
import 'package:hub/components/organism_components/local_profile_component/local_profile_component_widget.dart';
|
|
import 'package:hub/components/organism_components/menu_component/menu_component_widget.dart';
|
|
import 'package:hub/flutter_flow/flutter_flow_icon_button.dart';
|
|
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
|
|
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
|
import 'package:hub/pages/home_page/home_page_model.dart';
|
|
import 'package:hub/shared/utils/dialog_util.dart';
|
|
import 'package:hub/shared/widgets/drawer_widget/drawer_widget.dart';
|
|
|
|
class HomePageWidget extends StatefulWidget {
|
|
const HomePageWidget({Key? key});
|
|
|
|
@override
|
|
State<HomePageWidget> createState() => _HomePageWidgetState();
|
|
}
|
|
|
|
class _HomePageWidgetState extends State<HomePageWidget> {
|
|
late HomePageModel _model;
|
|
final scaffoldKey = GlobalKey<ScaffoldState>();
|
|
LocalProfileComponentWidget _localProfileComponentWidget =
|
|
const LocalProfileComponentWidget();
|
|
|
|
_HomePageWidgetState() {
|
|
log('HomePageWidget');
|
|
}
|
|
|
|
Future<void> checkData() async {
|
|
try {
|
|
final response = await PhpGroup.getDadosCall.call(
|
|
devUUID: AppState().devUUID,
|
|
userUUID: AppState().userUUID,
|
|
cliUUID: AppState().cliUUID,
|
|
atividade: 'getDados',
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
if (response.jsonBody['error'] == false) {
|
|
AppState().whatsapp = response.jsonBody['whatsapp'];
|
|
AppState().provisional = response.jsonBody['provisional'];
|
|
AppState().name = response.jsonBody['visitado']['VDO_NOME'];
|
|
safeSetState(() {});
|
|
} else {
|
|
final errorMsg = response.jsonBody['error_msg'];
|
|
if (errorMsg !=
|
|
r'''Usuario nao possui vínculo ativo com esse condominio''') {
|
|
log(errorMsg);
|
|
await DialogUtil.warningDefault(context)
|
|
.whenComplete(() => checkData());
|
|
safeSetState(() {});
|
|
}
|
|
}
|
|
} else {
|
|
await DialogUtil.warningDefault(context)
|
|
.whenComplete(() => checkData());
|
|
safeSetState(() {});
|
|
}
|
|
} catch (e) {
|
|
log('Error in checkData: $e');
|
|
await DialogUtil.warningDefault(context).whenComplete(() => checkData());
|
|
}
|
|
}
|
|
|
|
Future<void> checkLocal() async {
|
|
log('Checklocal');
|
|
try {
|
|
final response = await PhpGroup.getLocalsCall.call(
|
|
devUUID: AppState().devUUID,
|
|
userUUID: AppState().userUUID,
|
|
);
|
|
|
|
List<dynamic> locals = response.jsonBody['locais'] ?? [];
|
|
final activeLocals =
|
|
locals.where((local) => local['CLU_STATUS'] == 'A').toList();
|
|
|
|
if (activeLocals.isEmpty || AppState().cliUUID.isEmpty) {
|
|
await showBottomSheet().then((_) => checkData());
|
|
}
|
|
} catch (e) {
|
|
log('Error in checkLocal: $e');
|
|
await showBottomSheet().then((_) => checkData());
|
|
}
|
|
}
|
|
|
|
Future<void> showBottomSheet() async {
|
|
await showModalBottomSheet(
|
|
isScrollControlled: true,
|
|
backgroundColor: Colors.transparent,
|
|
enableDrag: false,
|
|
isDismissible: false,
|
|
context: context,
|
|
builder: (context) => Padding(
|
|
padding: MediaQuery.viewInsetsOf(context),
|
|
child: const BottomArrowLinkedLocalsComponentWidget(),
|
|
),
|
|
).then((_) => safeSetState(() {
|
|
_localProfileComponentWidget = const LocalProfileComponentWidget();
|
|
}));
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
_model = createModel(context, () => HomePageModel());
|
|
_model.updateOnChange = true;
|
|
|
|
AppState().context = context;
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
await checkLocal();
|
|
});
|
|
() async {
|
|
await FirebaseMessagingService().updateDeviceToken();
|
|
}();
|
|
|
|
_model.textController ??= TextEditingController();
|
|
_model.textFieldFocusNode ??= FocusNode();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_model.dispose();
|
|
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// context.watch<AppState>();
|
|
|
|
return GestureDetector(
|
|
onTap: () => _model.unfocusNode.canRequestFocus
|
|
? FocusScope.of(context).requestFocus(_model.unfocusNode)
|
|
: FocusScope.of(context).unfocus(),
|
|
child: Scaffold(
|
|
key: scaffoldKey,
|
|
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
|
// drawer: buildDrawer(context),
|
|
drawerEnableOpenDragGesture: true,
|
|
drawerDragStartBehavior: DragStartBehavior.start,
|
|
drawer: CustomDrawer(model: _model),
|
|
appBar: AppBar(
|
|
backgroundColor: FlutterFlowTheme.of(context).primary,
|
|
automaticallyImplyLeading: false,
|
|
leading: FlutterFlowIconButton(
|
|
borderRadius: 20.0,
|
|
borderWidth: 1.0,
|
|
buttonSize: 40.0,
|
|
fillColor: FlutterFlowTheme.of(context).primary,
|
|
icon: const Icon(
|
|
Icons.menu_rounded,
|
|
color: Colors.white,
|
|
size: 28.0,
|
|
),
|
|
onPressed: () async {
|
|
scaffoldKey.currentState!.openDrawer();
|
|
},
|
|
),
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(8.0),
|
|
child: Image.asset(
|
|
'assets/images/logo.png',
|
|
width: 15.0,
|
|
height: 15.0,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
Text(
|
|
'FRE ACCESS',
|
|
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
|
fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily,
|
|
color: FlutterFlowTheme.of(context).info,
|
|
letterSpacing: 0.0,
|
|
useGoogleFonts: GoogleFonts.asMap().containsKey(
|
|
FlutterFlowTheme.of(context).bodyMediumFamily),
|
|
),
|
|
),
|
|
].divide(const SizedBox(width: 8.0)),
|
|
),
|
|
actions: const [],
|
|
centerTitle: true,
|
|
elevation: 0.0,
|
|
),
|
|
body: buildPage(context),
|
|
),
|
|
);
|
|
}
|
|
|
|
Container buildPage(BuildContext context) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: FlutterFlowTheme.of(context).primary,
|
|
),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.max,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Wrap(
|
|
spacing: 0.0,
|
|
runSpacing: 0.0,
|
|
alignment: WrapAlignment.start,
|
|
crossAxisAlignment: WrapCrossAlignment.start,
|
|
direction: Axis.horizontal,
|
|
runAlignment: WrapAlignment.start,
|
|
verticalDirection: VerticalDirection.down,
|
|
clipBehavior: Clip.none,
|
|
children: [
|
|
createLocal(),
|
|
createBody(),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget createBody() {
|
|
return Container(
|
|
color: FlutterFlowTheme.of(context).primaryBackground,
|
|
child: wrapWithModel(
|
|
model: _model.menuComponentModel,
|
|
updateCallback: () => setState(() {}),
|
|
child: const Padding(
|
|
padding: EdgeInsets.only(bottom: 40),
|
|
child: MenuComponentWidget(
|
|
expandable: true,
|
|
style: MenuView.list_grid,
|
|
item: MenuItem.button,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget createLocal() {
|
|
return wrapWithModel(
|
|
model: _model.localComponentModel,
|
|
updateCallback: () => safeSetState(() {}),
|
|
child: _localProfileComponentWidget,
|
|
);
|
|
}
|
|
}
|