304 lines
9.7 KiB
Dart
304 lines
9.7 KiB
Dart
// 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<MessageHistoryPageWidget> createState() =>
|
|
_MessageHistoryPageWidgetState();
|
|
}
|
|
|
|
class _MessageHistoryPageWidgetState extends State<MessageHistoryPageWidget> with TickerProviderStateMixin {
|
|
late MessageHistoryPageModel _model;
|
|
|
|
final scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_model = createModel(context, () => MessageHistoryPageModel());
|
|
|
|
_model.tabBarController = TabController(
|
|
vsync: this,
|
|
length: 3,
|
|
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<FFAppState>();
|
|
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, 'T'),
|
|
]
|
|
)),
|
|
].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<ApiCallResponse>(
|
|
future: PhpGroup.getMessagesCall.call(
|
|
devUUID: FFAppState().devUUID.toString(),
|
|
userUUID: FFAppState().userUUID.toString(),
|
|
cliID: FFAppState().cliUUID.toString(),
|
|
atividade: 'getMensagens',
|
|
pageSize: '100',
|
|
pageNumber: '1',
|
|
tipoDestino: DestIndex,
|
|
).catchError((error) {
|
|
log('Error: ${error.toString()}');
|
|
return Future.delayed(Duration(seconds: 1), () {
|
|
return Center(
|
|
child: Text('Erro ao carregar mensagens'),
|
|
);
|
|
});
|
|
}),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return Center(
|
|
child: SizedBox(
|
|
width: 50.0,
|
|
height: 50.0,
|
|
child: SpinKitCircle(
|
|
color: FlutterFlowTheme.of(context).primary,
|
|
size: 50.0,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
if (snapshot.hasError == true || snapshot.data == null) {
|
|
log('Error: ${snapshot.error.toString()}');
|
|
// log('Error: ${snapshot.data!.jsonBody['mensagens']}');
|
|
return const Center(
|
|
child: Text('Erro ao carregar mensagens'),
|
|
);
|
|
}
|
|
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],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
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.spaceBetween,
|
|
mainAxisSize: MainAxisSize.max,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 15.0),
|
|
child: Text(
|
|
jsonBody['MSG_DATE'].toString(),
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 16,
|
|
color: FlutterFlowTheme.of(context).primary,
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 15.0),
|
|
child: Container(
|
|
width: 100, // Adjust the width as needed
|
|
child: Text(
|
|
jsonBody['MSG_ORIGEM_DESC'].toString(),
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 16,
|
|
color: FlutterFlowTheme.of(context).primary,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
),
|
|
Icon(jsonBody['MSG_DESTINO_TP'] == 'T'
|
|
? Icons.group
|
|
: Icons.person, color: FlutterFlowTheme.of(context).accent1,),
|
|
],
|
|
),
|
|
Text(jsonBody['MSG_TEXTO'].toString()),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
|
|
}
|