// import 'dart:js_interop'; import 'dart:convert'; import 'dart:developer'; import 'package:hub/commons/actions/api_calls.dart'; import 'package:hub/commons/actions/actions.dart'; import 'package:hub/commons/actions/api_manager.dart'; import 'package:hub/commons/actions/pushNotificationService.dart'; import 'package:hub/commons/components/molecules/card/widget.dart'; import 'package:hub/modals/notifications/visit_request/widget.dart'; import 'package:json_path/fun_extra.dart'; import '/commons/widgets/flutter_flow_icon_button.dart'; import '/commons/widgets/flutter_flow_theme.dart'; import '/commons/widgets/flutter_flow_util.dart'; import '/commons/widgets/custom_functions.dart' as functions; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:provider/provider.dart'; import 'model.dart'; class MessageHistoryPageWidget extends StatefulWidget { const MessageHistoryPageWidget({super.key}); @override State createState() => _MessageHistoryPageWidgetState(); } class _MessageHistoryPageWidgetState extends State with TickerProviderStateMixin { late MessageHistoryPageModel _model; final scaffoldKey = GlobalKey(); @override void initState() { super.initState(); _model = createModel(context, () => MessageHistoryPageModel()); _model.tabBarController = TabController( vsync: this, length: 4, initialIndex: 1, )..addListener(() => setState(() {})); _model.textController ??= TextEditingController(); _model.textFieldFocusNode ??= FocusNode(); } @override void dispose() { _model.dispose(); super.dispose(); } void onUpdate(BuildContext context) { _model.clearGetLiberationsCache(); setState(() {}); } @override Widget build(BuildContext context) { context.watch(); 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, appBar: appBarMessage(context), body: bodyMessage(context, _model), ), ); } } PreferredSizeWidget appBarMessage(BuildContext context) { return AppBar( backgroundColor: FlutterFlowTheme.of(context).primaryBackground, automaticallyImplyLeading: false, leading: FlutterFlowIconButton( borderColor: Colors.transparent, borderRadius: 30.0, borderWidth: 1.0, buttonSize: 60.0, icon: Icon( Icons.keyboard_arrow_left, color: FlutterFlowTheme.of(context).primaryText, size: 30.0, ), onPressed: () async { context.pop(); }, ), title: Text( FFLocalizations.of(context).getVariableText( enText: 'Message History', ptText: 'Histórico de Mensagens', ), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: 'Nunito', color: FlutterFlowTheme.of(context).primaryText, fontSize: 17.0, letterSpacing: 0.0, useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), ), ), actions: const [], centerTitle: true, ); } Widget bodyMessage( BuildContext context, MessageHistoryPageModel _model) { return SafeArea( top: true, child: Column( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, children: [ Align( alignment: const Alignment(0.0, 0), child: TabBar( labelColor: FlutterFlowTheme.of(context).primaryText, unselectedLabelColor: FlutterFlowTheme.of(context).primaryText, labelStyle: FlutterFlowTheme.of(context).titleMedium.override( fontFamily: FlutterFlowTheme.of(context).titleMediumFamily, fontSize: 13.0, letterSpacing: 0.0, useGoogleFonts: GoogleFonts.asMap().containsKey( FlutterFlowTheme.of(context).titleMediumFamily), ), unselectedLabelStyle: const TextStyle(), indicatorColor: FlutterFlowTheme.of(context).primary, padding: const EdgeInsets.all(4.0), tabs: [ Tab( text: FFLocalizations.of(context).getVariableText( ptText: 'Pessoal', enText: 'Personal', ), ), Tab( text: FFLocalizations.of(context).getVariableText( enText: 'All', ptText: 'Todos', ), ), Tab( text: FFLocalizations.of(context).getVariableText( ptText: 'Global', enText: 'Global', ), ), ], controller: _model.tabBarController, onTap: (i) async { [() async {}, () async {}][i](); }, ), ), Expanded(child: TabBarView( controller: _model.tabBarController, children: [ liberationDynamicListView(context, _model, 'P'), liberationDynamicListView(context, _model, 'A'), liberationDynamicListView(context, _model, 'A'), ] )), ].addToStart(const SizedBox(height: 0)), ), ); } Widget liberationDynamicListView( BuildContext context, MessageHistoryPageModel _model, String DestIndex ) { return Container( width: double.infinity, height: double.infinity, decoration: const BoxDecoration(), child: FutureBuilder( future: PhpGroup.getMessagesCall.call( devUUID: FFAppState().devUUID.toString(), userUUID: FFAppState().userUUID.toString(), cliID: FFAppState().cliUUID.toString(), atividade: 'getMensagens', pageSize: '100', pageNumber: '1', tipoDestino: DestIndex, ), builder: (context, snapshot) { // return SizedBox(); if (!snapshot.hasData) { return Center( child: SizedBox( width: 50.0, height: 50.0, child: SpinKitCircle( color: FlutterFlowTheme.of(context).primary, size: 50.0, ), ), ); } // final columnGetLiberationsResponse = snapshot.data!; // final liberationHistory = PhpGroup.getLiberationsCall // .rqList( // columnGetLiberationsResponse.jsonBody, // ) // ?.toList() ?? // []; // final filteredLiberationHistory = _model.textController.text.isNotEmpty // ? liberationHistory // .where((item) => functions // .jsonToStr(getJsonField( // item, // r'''$.VTE_NOME''', // )) // .toLowerCase() // .contains( // _model.textController.text.toLowerCase(), // )) // .toList() // : liberationHistory; return ListView.builder( itemCount: snapshot.data!.jsonBody['total_rows'], addAutomaticKeepAlives: false, addRepaintBoundaries: true, cacheExtent: 1000.0, itemBuilder: (BuildContext context, int index) { return messageHistoryItem(context, snapshot.data!.jsonBody['mensagens'][index]); // final liberationHistoryItem = snapshot.data.jsonBody[index]; // return Padding( // padding: EdgeInsets.only( // top: index == 0 // ? MediaQuery.of(context).size.height * 0.075 // : 8.0, // left: 8.0, // right: 8.0, // bottom: 8.0, // ), // child: Align( // alignment: AlignmentDirectional(0.0, 0.0), // child: messageHistoryItem( // context, // liberationHistoryItem, // ), // ), // ); }, ); }, ), ); } Widget messageHistoryItem( BuildContext context, dynamic jsonBody) { log(jsonBody.toString()); return Padding( padding: const EdgeInsets.symmetric(horizontal: 15), child: Card( child: Container( // height: 100, child: Padding( padding: const EdgeInsets.all(8.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Row( mainAxisAlignment: MainAxisAlignment.end, mainAxisSize: MainAxisSize.max, children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 15.0), child: Text(jsonBody['MSG_ORIGEM_DESC'].toString(), style: TextStyle( fontWeight: FontWeight.bold, fontSize: 16, color: FlutterFlowTheme.of(context).primary, ),), ), Icon(jsonBody['MSG_ORIGEM'] == '20'? Icons.person : Icons.group), ], ), Text(jsonBody['MSG_TEXTO'].toString()), ], ), ), ), ), ); }