mobileApplicationsKonectarApp/lib/views/interaction_module/interactionlistscreen.dart

157 lines
6.7 KiB
Dart
Raw Permalink Normal View History

2024-01-04 07:06:37 +00:00
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pwa_ios/main.dart';
2024-01-04 07:06:37 +00:00
import 'package:pwa_ios/model/save_interaction.dart';
import 'package:pwa_ios/utils/util.dart';
import 'package:pwa_ios/viewmodel/interactionprovider.dart';
import 'package:pwa_ios/views/interaction_module/interaction_screen.dart';
import 'package:pwa_ios/views/interaction_module/view_forms_list.dart';
class InteractionListScreen extends StatefulWidget {
const InteractionListScreen({super.key});
@override
State<InteractionListScreen> createState() => _InteractionListScreenState();
}
class _InteractionListScreenState extends State<InteractionListScreen> {
List<SaveInteraction> savedList = [];
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
if (!mytimer!.isActive) {
activateTimer();
}
2024-01-04 07:06:37 +00:00
init();
});
super.initState();
}
init() async {
await Provider.of<InteractionProvider>(context, listen: false)
.initConfigData();
await Provider.of<InteractionProvider>(context, listen: false).getRecords();
setState(() {});
}
Future<int> getCount(String form, InteractionProvider provider) async {
await provider.getRecords();
2024-01-04 07:06:37 +00:00
return provider.savedList.where((element) => element.form == form).length;
}
@override
Widget build(BuildContext context) {
return Consumer<InteractionProvider>(
builder: (BuildContext context, provider, Widget? child) {
return Scaffold(
appBar: AppBar(
title: Text(
'Interaction Forms',
style: TextStyle(fontSize: isTablet ? 22 : 14, color: Colors.white),
),
automaticallyImplyLeading: false,
backgroundColor: const Color(0xFF2b9af3),
),
body: Container(
child: Center(
child: ListView.builder(
itemCount: provider.intConfigDataList.length,
cacheExtent: double.parse(
provider.intConfigDataList.length.toString()),
itemBuilder: (context, index) {
return Column(
children: [
ListTile(
title: Row(
children: [
Text(
provider.intConfigDataList[index].name,
2024-01-04 07:06:37 +00:00
),
const SizedBox(
width: 20,
),
IconButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
InteractionScreen(
index: index,
form: provider
.intConfigDataList[index]
.name,
2024-01-04 07:06:37 +00:00
)));
},
icon: const Icon(
Icons.arrow_circle_right_outlined,
size: 30,
color: Color.fromARGB(255, 8, 39, 92),
),
),
],
),
trailing: provider.savedList.indexWhere((element) =>
element.form ==
provider.intConfigDataList[index].name) !=
2024-01-04 07:06:37 +00:00
-1
? InkWell(
onTap: () {
if (getCount(
provider
.intConfigDataList[index].name,
2024-01-04 07:06:37 +00:00
provider) !=
0) {
List<SaveInteraction> sendsavedList =
provider
.savedList
.where((element) =>
element.form ==
provider
.intConfigDataList[index]
.name)
.toList();
2024-01-04 07:06:37 +00:00
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
SavedFormListScreen(
formname: provider
.intConfigDataList[
index]
.name,
2024-01-04 07:06:37 +00:00
)));
}
},
child: Text(
"${provider.savedList.where((element) => element.form == provider.intConfigDataList[index].name).length} record(s) saved",
2024-01-04 07:06:37 +00:00
style: TextStyle(
fontSize: isTablet ? 18.0 : 14,
color: Colors.blue.shade900),
),
)
: const SizedBox.shrink(),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
InteractionScreen(
index: index,
form: provider
.intConfigDataList[index].name,
2024-01-04 07:06:37 +00:00
)));
},
),
const Divider(),
],
);
})),
),
);
});
}
}