flutter-freaccess-hub/lib/pages/home_page/home_page_widget.dart

924 lines
39 KiB
Dart

// import 'package:hub/backend/push_notification/pushNotification.dart';
import 'dart:developer';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart';
import 'package:hub/actions/actions.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/components/organism_components/message_well_component/message_well_component_widget.dart';
import 'package:hub/flutter_flow/custom_functions.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/flutter_flow/flutter_flow_widgets.dart';
import 'package:hub/flutter_flow/nav/nav.dart';
import 'package:hub/main.dart';
import 'package:hub/pages/home_page/home_page_model.dart';
import 'package:provider/provider.dart';
// Crude counter to make messages unique
int _messageCount = 0;
/// The API endpoint here accepts a raw FCM payload for demonstration purposes.
String constructFCMPayload(String? token) {
_messageCount++;
return jsonEncode({
'token': token,
'data': {
'via': 'FlutterFire Cloud Messaging!!!',
'count': _messageCount.toString(),
},
'notification': {
'title': 'Hello FlutterFire!',
'body': 'This notification (#$_messageCount) was created via FCM!',
},
});
}
class HomePageWidget extends StatefulWidget {
const HomePageWidget({super.key});
@override
State<HomePageWidget> createState() => _HomePageWidgetState();
}
class _HomePageWidgetState extends State<HomePageWidget> {
late HomePageModel _model;
bool localStatus = false;
final scaffoldKey = GlobalKey<ScaffoldState>();
String? _token;
String? initialMessage;
bool _resolved = false;
Future<void> checkLocalStatus() async {
localStatus = await checkLocals(
context: context,
model: _model,
safeSetState: safeSetState,
);
}
@override
void initState() {
super.initState();
_model = createModel(context, () => HomePageModel());
FirebaseMessaging.instance
.getInitialMessage()
.then(
(value) => setState(
() {
_resolved = true;
initialMessage = value?.data.toString();
log('getInitialMessage resolved');
},
),
)
.whenComplete(() => log('getInitialMessage completed'));
FirebaseMessaging.onMessage.listen(showFlutterNotification).onDone(() {
log('onMessage completed');
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
log('A new onMessageOpenedApp event was published!');
});
AppState().context = context;
WidgetsBinding.instance.addPostFrameCallback((_) async {
@override
void initState() {
super.initState();
checkLocalStatus();
}
// Rest of your code...
if (AppState().cliUUID == null || AppState().cliUUID.isEmpty) {
showModalBottomSheet(
isScrollControlled: false,
backgroundColor: Colors.transparent,
enableDrag: false,
isDismissible: false,
context: context,
builder: (context) {
return GestureDetector(
onTap: () => _model.unfocusNode.canRequestFocus
? FocusScope.of(context).requestFocus(_model.unfocusNode)
: FocusScope.of(context).unfocus(),
child: Padding(
padding: MediaQuery.viewInsetsOf(context),
child: const BottomArrowLinkedLocalsComponentWidget(),
),
);
},
).then((value) => safeSetState(() {}));
} else {
return;
}
});
_model.textController ??= TextEditingController();
_model.textFieldFocusNode ??= FocusNode();
}
@override
void dispose() {
_model.dispose();
super.dispose();
}
Future<void> sendPushMessage() async {
if (_token == null) {
log('Unable to send FCM message, no token exists.');
return;
}
try {
await post(
Uri.parse('https://api.rnfirebase.io/messaging/send'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: constructFCMPayload(_token),
);
log('FCM request for device sent!');
} catch (e) {
log(e.toString());
}
}
Future<void> onActionSelected(String value) async {
switch (value) {
case 'subscribe':
{
log(
'FlutterFire Messaging Example: Subscribing to topic "fcm_test".',
);
await FirebaseMessaging.instance.subscribeToTopic('fcm_test');
log(
'FlutterFire Messaging Example: Subscribing to topic "fcm_test" successful.',
);
}
break;
case 'unsubscribe':
{
log(
'FlutterFire Messaging Example: Unsubscribing from topic "fcm_test".',
);
await FirebaseMessaging.instance.unsubscribeFromTopic('fcm_test');
log(
'FlutterFire Messaging Example: Unsubscribing from topic "fcm_test" successful.',
);
}
break;
case 'get_apns_token':
{
if (defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS) {
log('FlutterFire Messaging Example: Getting APNs token...');
String? token = await FirebaseMessaging.instance.getAPNSToken();
log('FlutterFire Messaging Example: Got APNs token: $token');
} else {
log(
'FlutterFire Messaging Example: Getting an APNs token is only supported on iOS and macOS platforms.',
);
}
}
break;
default:
break;
}
}
@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).secondaryBackground,
drawer: buildDrawer(context),
body: buildPage(context, localStatus),
),
);
}
Container buildPage(BuildContext context, bool localStatus) {
return Container(
decoration: BoxDecoration(
color: FlutterFlowTheme.of(context).primaryBackground,
),
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: [
createHeader(context),
createLocal(localStatus),
createBody(),
],
),
],
),
),
);
}
Wrap createBody() {
return 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: [
wrapWithModel(
model: _model.menuComponentModel,
updateCallback: () => setState(() {}),
child: const MenuComponentWidget(
expandable: true,
style: MenuView.list_grid,
item: MenuItem.button,
),
),
Align(
alignment: const AlignmentDirectional(0.0, 0.0),
child: Provider<MessageWellNotifier>(
create: (_) => MessageWellNotifier(),
child: wrapWithModel(
model: _model.messageWellComponentModel,
updateCallback: () => setState(() {}),
child: const MessageWellComponentWidget(),
),
),
),
//footer
const SizedBox(
height: 100,
width: double.infinity,
)
],
);
}
Widget createLocal(bool localStatus) {
return wrapWithModel(
model: _model.localComponentModel,
updateCallback: () => setState(() {}),
child: LocalProfileComponentWidget(
localStatus: localStatus,
),
);
}
Row createHeader(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Container(
width: 100.0,
height: 100.0,
decoration: const BoxDecoration(
color: Color(0xFF1AAB5F),
),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Align(
alignment: const AlignmentDirectional(0.0, 1.0),
child: Container(
height: 50.0,
decoration: const BoxDecoration(),
child: Align(
alignment: const AlignmentDirectional(0.0, 0.0),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
Align(
alignment: const AlignmentDirectional(-1.0, 0.0),
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
10.0, 0.0, 0.0, 0.0),
child: 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();
},
),
),
),
Align(
alignment: const AlignmentDirectional(-1.0, 0.0),
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
60.0, 15.0, 0.0, 0.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.network(
'https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/8r2vsbd9i03k/logo.png',
width: 50.0,
height: 200.0,
fit: BoxFit.none,
),
),
),
),
Align(
alignment: const AlignmentDirectional(0.0, 0.0),
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
0.0, 15.0, 0.0, 0.0),
child: Text(
FFLocalizations.of(context).getText(
'rg9pzkpz' /* 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),
),
),
),
),
],
),
),
),
),
Align(
alignment: const AlignmentDirectional(0.0, 1.0),
child: Container(
width: 100.0,
height: 50.0,
decoration: const BoxDecoration(),
child: Align(
alignment: const AlignmentDirectional(1.0, 1.0),
child: FlutterFlowIconButton(
borderRadius: 20.0,
borderWidth: 1.0,
buttonSize: 40.0,
icon: Icon(
Icons.notifications_sharp,
color: FlutterFlowTheme.of(context).info,
size: 24.0,
),
onPressed: () {},
),
),
),
),
],
),
),
),
],
);
}
SizedBox buildDrawer(BuildContext context) {
return SizedBox(
width: 750.0,
child: Drawer(
elevation: 16.0,
child: Container(
decoration: BoxDecoration(
color: FlutterFlowTheme.of(context).primaryBackground,
shape: BoxShape.rectangle,
),
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: double.infinity,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5.0),
bottomRight: Radius.circular(5.0),
topLeft: Radius.circular(0.0),
topRight: Radius.circular(0.0),
),
shape: BoxShape.rectangle,
),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(30, 30, 10, 0),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: Container(
width: double.infinity,
decoration: const BoxDecoration(),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
width: 50.0,
height: 50.0,
clipBehavior: Clip.antiAlias,
decoration: const BoxDecoration(
shape: BoxShape.circle,
),
child: Image.network(
valueOrDefault<String>(
'https://freaccess.com.br/freaccess/Images/Clients/${AppState().cliUUID}.png',
'https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/7ftdetkzc3s0/360_F_64676383_LdbmhiNM6Ypzb3FM4PPuFP9rHe7ri8Ju.jpg',
),
fit: BoxFit.cover,
),
),
Container(
width: 150.0,
child: Text(
valueOrDefault<String>(
convertToUppercase(AppState().local),
'NOME DO LOCAL',
),
style: FlutterFlowTheme.of(context)
.bodyLarge
.override(
fontFamily: 'Nunito Sans',
color: FlutterFlowTheme.of(context)
.primaryText,
fontSize: 14.0,
letterSpacing: 0.0,
fontWeight: FontWeight.normal,
useGoogleFonts: GoogleFonts.asMap()
.containsKey('Nunito Sans'),
),
),
),
].divide(const SizedBox(width: 20.0)),
),
),
),
Container(
width: 50.0,
child: Container(
height: 30.0,
decoration: const BoxDecoration(),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Flexible(
child: FlutterFlowIconButton(
borderRadius: 100.0,
borderWidth: 1.0,
buttonSize: 40.0,
icon: Icon(
Icons.close_sharp,
color: FlutterFlowTheme.of(context)
.primary,
size: 20.0,
),
onPressed: () async {
if (scaffoldKey
.currentState!.isDrawerOpen ||
scaffoldKey.currentState!
.isEndDrawerOpen) {
Navigator.pop(context);
}
},
),
),
],
),
),
),
]
.divide(const SizedBox(width: 0.0))
.around(const SizedBox(width: 0.0)),
),
),
].addToStart(const SizedBox(height: 30.0)),
),
),
Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(0.0, 10.0, 0.0, 0.0),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Flexible(
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
8.0, 0.0, 8.0, 0.0),
child: TextFormField(
controller: _model.textController,
focusNode: _model.textFieldFocusNode,
autofocus: false,
obscureText: false,
decoration: InputDecoration(
isDense: true,
labelStyle: FlutterFlowTheme.of(context)
.labelMedium
.override(
fontFamily: FlutterFlowTheme.of(context)
.labelMediumFamily,
color:
FlutterFlowTheme.of(context).primaryText,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap()
.containsKey(FlutterFlowTheme.of(context)
.labelMediumFamily),
),
alignLabelWithHint: false,
hintStyle: FlutterFlowTheme.of(context)
.labelMedium
.override(
fontFamily: FlutterFlowTheme.of(context)
.labelMediumFamily,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap()
.containsKey(FlutterFlowTheme.of(context)
.labelMediumFamily),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color:
FlutterFlowTheme.of(context).customColor1,
width: 0.5,
),
borderRadius: BorderRadius.circular(2.0),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: FlutterFlowTheme.of(context).primary,
width: 0.5,
),
borderRadius: BorderRadius.circular(2.0),
),
errorBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: FlutterFlowTheme.of(context).error,
width: 0.5,
),
borderRadius: BorderRadius.circular(2.0),
),
focusedErrorBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: FlutterFlowTheme.of(context).error,
width: 0.5,
),
borderRadius: BorderRadius.circular(2.0),
),
prefixIcon: const Icon(
Icons.search_sharp,
),
),
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: FlutterFlowTheme.of(context)
.bodyMediumFamily,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap().containsKey(
FlutterFlowTheme.of(context)
.bodyMediumFamily),
),
validator: _model.textControllerValidator
.asValidator(context),
),
),
),
]
.addToStart(const SizedBox(width: 30.0))
.addToEnd(const SizedBox(width: 30.0)),
),
),
Expanded(
child: wrapWithModel(
model: _model.menuComponentModel,
updateCallback: () => setState(() {}),
child: MenuComponentWidget(
expandable: false,
style: MenuView.list,
item: MenuItem.card,
),
),
),
FFButtonWidget(
onPressed: () async {
AppState().deleteAll();
setState(() {});
context.goNamed(
'welcomePage',
extra: <String, dynamic>{
kTransitionInfoKey: const TransitionInfo(
hasTransition: true,
transitionType: PageTransitionType.scale,
alignment: Alignment.bottomCenter,
),
},
);
},
text: FFLocalizations.of(context).getText(
'xx0db4wi' /* Sair */,
),
options: FFButtonOptions(
height: 40.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: const Color(0x00D70000),
textStyle: FlutterFlowTheme.of(context).labelMedium.override(
fontFamily: 'Plus Jakarta Sans',
color: FlutterFlowTheme.of(context).primaryText,
fontSize: 14.0,
letterSpacing: 0.0,
fontWeight: FontWeight.w500,
useGoogleFonts: GoogleFonts.asMap()
.containsKey('Plus Jakarta Sans'),
),
elevation: 0.0,
borderSide: const BorderSide(
width: 0.0,
),
borderRadius: BorderRadius.circular(50.0),
),
),
].addToEnd(const SizedBox(height: 64.0)),
),
),
),
);
// body: Container(
// decoration: BoxDecoration(
// color: FlutterFlowTheme.of(context).primaryBackground,
// ),
// 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: [
// Row(
// mainAxisSize: MainAxisSize.max,
// children: [
// Expanded(
// child: Container(
// width: 100.0,
// height: 100.0,
// decoration: const BoxDecoration(
// color: Color(0xFF1AAB5F),
// ),
// child: Row(
// mainAxisSize: MainAxisSize.min,
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Align(
// alignment: const AlignmentDirectional(0.0, 1.0),
// child: Container(
// height: 50.0,
// decoration: const BoxDecoration(),
// child: Align(
// alignment: const AlignmentDirectional(0.0, 0.0),
// child: Row(
// mainAxisSize: MainAxisSize.max,
// children: [
// Align(
// alignment:
// const AlignmentDirectional(-1.0, 0.0),
// child: Padding(
// padding: const EdgeInsetsDirectional
// .fromSTEB(
// 10.0, 0.0, 0.0, 0.0),
// child: 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();
// },
// ),
// ),
// ),
// Align(
// alignment:
// const AlignmentDirectional(-1.0, 0.0),
// child: Padding(
// padding: const EdgeInsetsDirectional
// .fromSTEB(
// 60.0, 15.0, 0.0, 0.0),
// child: ClipRRect(
// borderRadius:
// BorderRadius.circular(8.0),
// child: Image.network(
// 'https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/8r2vsbd9i03k/logo.png',
// width: 50.0,
// height: 200.0,
// fit: BoxFit.none,
// ),
// ),
// ),
// ),
// Align(
// alignment:
// const AlignmentDirectional(0.0, 0.0),
// child: Padding(
// padding: const EdgeInsetsDirectional
// .fromSTEB(
// 0.0, 15.0, 0.0, 0.0),
// child: Text(
// FFLocalizations.of(context)
// .getText(
// 'rg9pzkpz' /* 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),
// ),
// ),
// ),
// ),
// ],
// ),
// ),
// ),
// ),
// Align(
// alignment: const AlignmentDirectional(0.0, 1.0),
// child: Container(
// width: 100.0,
// height: 50.0,
// decoration: const BoxDecoration(),
// child: Align(
// alignment: const AlignmentDirectional(1.0, 1.0),
// child: FlutterFlowIconButton(
// borderRadius: 20.0,
// borderWidth: 1.0,
// buttonSize: 40.0,
// icon: Icon(
// Icons.notifications_sharp,
// color:
// FlutterFlowTheme.of(context).info,
// size: 24.0,
// ),
// onPressed: () {
// print('IconButton pressed ...');
// },
// ),
// ),
// ),
// ),
// ],
// ),
// ),
// ),
// ],
// ),
// wrapWithModel(
// model: _model.localComponentModel,
// updateCallback: () => setState(() {}),
// child: const LocalProfileComponentWidget(),
// ),
// 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: [
// wrapWithModel(
// model: _model.menuComponentModel,
// updateCallback: () => setState(() {}),
// child: const MenuComponentWidget(),
// ),
// Align(
// alignment: const AlignmentDirectional(0.0, 0.0),
// child: wrapWithModel(
// model: _model.messageWellComponentModel,
// updateCallback: () => setState(() {}),
// child: const MessageWellComponentWidget(),
// ),
// ),
// ],
// ),
// ],
// ),
// ],
// ),
// ),
// ),
// ),
// );
}
}
/// UI Widget for displaying metadata.
class MetaCard extends StatelessWidget {
final String _title;
final Widget _children;
// ignore: public_member_api_docs
MetaCard(this._title, this._children);
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
margin: const EdgeInsets.only(left: 8, right: 8, top: 8),
child: Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
Container(
margin: const EdgeInsets.only(bottom: 16),
child: Text(_title, style: const TextStyle(fontSize: 18)),
),
_children,
],
),
),
),
);
}
}