Untitled
unknown
plain_text
2 years ago
39 kB
8
Indexable
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:the_citizen_app/src/pages/my_queries_page.dart';
import '../config/app_theme.dart';
import '../config/base.dart';
import '../helpers/hex_color.dart';
import '../helpers/k_text.dart';
import '../helpers/loading.dart';
import '../helpers/route.dart';
import '../hive_models/language_model.dart';
import '../hive_models/shout_categories.dart';
import '../hive_models/shout_sub_categories.dart';
import '../utility/utility.dart';
import 'report_issue_page.dart';
class ReportCategoryPage extends StatefulWidget {
@override
State<ReportCategoryPage> createState() => _ReportCategoryPageState();
}
class _ReportCategoryPageState extends State<ReportCategoryPage> with Base {
@override
Widget build(BuildContext context) {
ScrollController scrollController = ScrollController();
2.delay();
// shoutC.getShoutCategory();
return Scaffold(
body: Obx(() => shoutC.isLoading.value
? SizedBox(
height: Get.height / 1.5,
child: Center(
child: Loading(),
),
)
:
// SizedBox(
// height: Get.height / 1.5,
// child: Center(child: KText(text: 'No data found')),
// )
// :
ValueListenableBuilder(
valueListenable: Hive.box<List<ShoutCategories>>(('shoutCategories')).listenable(),
builder: (context, value, child) {
final selectedlang = appsettingsC.languageListBox.get('selectedLanguage',
defaultValue: LanguageModel(languageCode: "ENG", languageName: "English", localLanguage: "English"));
final shoutCat = value.get('shoutCategoryList*${selectedlang!.languageCode!}');
return shoutCat == null
? SizedBox(
height: Get.height / 1.5,
child: Center(
child: Loading(),
),
)
: shoutCat.isEmpty
? SizedBox(
height: Get.height / 1.5,
child: Center(child: KText(text: 'No data found')),
)
: Container(
color: hexToColor('#F5F9FC'),
child: Obx(
() => ListView.builder(
controller: scrollController,
key: Key('builder ${shoutC.selectedIndex.toString()}'),
// key: Key('builder ${selectedIndex.toString()}'),
padding: EdgeInsets.all(0),
physics: BouncingScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: shoutCat.length,
itemBuilder: (BuildContext context, int index) {
final item = shoutCat[index];
return InkWell(
onTap: () {
// shoutC.getShoutSubCategory(item.categoryCode!);
},
child: Obx(
() => Column(
children: [
Container(
decoration: BoxDecoration(
border: Border(
bottom: shoutC.expansionIndex.value == index
? BorderSide.none
: BorderSide(color: AppTheme.newAppBarTextColor, width: 0.5)),
color: shoutC.expansionIndex.value == index ? hexToColor('#E6EDF5') : Colors.white,
// gradient: LinearGradient(
// begin: Alignment.topCenter,
// end: Alignment.bottomCenter,o
// colors: [
// Color(0xffF5F9Fc),
// Color(0xffFFFFFF),
// Color(0xffFFFFFF),
// Color(0xffFFFFFF),
// ],
// ),
// boxShadow: [
// BoxShadow(
// color: hexToColor('#8DA3AC'),
// spreadRadius: 3,
// blurRadius: 5,
// offset:
// Offset(0, 3), // changes position of shadow
// ),
// ],
),
child: Theme(
data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
child: Container(
padding: EdgeInsets.symmetric(vertical: 10),
height: 70,
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey, width: 0.5)),
),
child: GestureDetector(
onTap: () {
if (shoutC.expansionIndex.value == index) {
shoutC.expansionIndex.value = -1;
} else {
shoutC.expansionIndex.value = index;
}
},
child: ListTile(
leading: item.categoryImage != null
? ImageIcon(
MemoryImage(Utility.uint8ListFromBase64String(item.categoryImage!)),
size: 40,
color: item.themeColor != null && item.themeColor != ""
? hexToColor('${item.themeColor!}')
: AppTheme.appBarColor,
)
: ImageIcon(
AssetImage('assets/images/shout_logo.png'),
size: 40,
color: AppTheme.appBarColor,
),
title: Text(
item.translatedName!,
style: TextStyle(
fontFamily: 'Manrope',
fontSize: 15.0,
fontWeight: FontWeight.w500,
),
),
trailing: shoutC.expansionIndex.value == index
? Icon(
Icons.keyboard_arrow_up_outlined,
size: 35,
)
: Icon(
Icons.keyboard_arrow_down_outlined,
size: 35,
),
),
),
)
// ExpansionTile(
// tilePadding: EdgeInsets.symmetric(vertical: 3, horizontal: 15),
// key: Key(index.toString()),
// iconColor: hexToColor('#8F94AC'),
// textColor: Colors.black,
// backgroundColor: hexToColor('#F5F9FC'),
// childrenPadding: EdgeInsets.zero,
// //initiallyExpanded: false,
// initiallyExpanded: shoutC.selectedIndex.value == index,
// onExpansionChanged: ((newState) {
// kLog(newState);
// scrollController.animateTo((Get.height * 3) * index,
// duration: Duration(seconds: 01), curve: Curves.bounceIn);
// shoutC.selectedIndex.value = index;
// shoutC.selectedIndex.value = index;
// }),
// leading: item.categoryImage != null
// ? ImageIcon(
// MemoryImage(Utility.uint8ListFromBase64String(item.categoryImage!)),
// size: 40,
// color: item.themeColor != null && item.themeColor != ""
// ? hexToColor('${item.themeColor!}')
// : AppTheme.appBarColor,
// )
// : ImageIcon(
// AssetImage('assets/images/shout_logo.png'),
// size: 40,
// color: AppTheme.appBarColor,
// ),
// title: Text(
// item.categoryName != ""
// ? ((language == '0' || language == null) ? '${item.categoryName}' : '${item.categoryName}')
// : 'No Title ',
// style: TextStyle(
// fontFamily: 'Manrope',
// fontSize: 15.0,
// fontWeight: FontWeight.w500,
// ),
// ),
// children: [
// Obx(
// () => Container(
// color: hexToColor('#E6EDF5'),
// height: Get.height / 3,
// child: shoutC.getShoutSubCategoryById(code: item.categoryCode!).isNotEmpty
// ? Obx(
// () => GridView.builder(
// shrinkWrap: true,
// scrollDirection: Axis.vertical,
// padding: EdgeInsets.all(5),
// physics: const BouncingScrollPhysics(),
// gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
// mainAxisExtent: 130.0,
// crossAxisCount: 3,
// ),
// itemBuilder: (BuildContext context, int index) {
// final subItems = shoutC.getShoutSubCategoryById(code: item.categoryCode!)[index];
// return ReportSubCategoryWidget(
// subCategory: subItems,
// );
// },
// itemCount: shoutC.getShoutSubCategoryById(code: item.categoryCode!).length,
// ),
// )
// : Container(
// child: Center(
// child: Text(
// 'Type not available!',
// style: TextStyle(
// color: Colors.black,
// ),
// ),
// ),
// ),
// ),
// )
// ],
// ),
),
),
if (shoutC.expansionIndex.value == index)
ValueListenableBuilder(
valueListenable:
Hive.box<List<ShoutSubCategories>>('shoutSubCategories').listenable(),
builder: (context, value, child) {
final selectedlang = appsettingsC.languageListBox.get('selectedLanguage',
defaultValue: LanguageModel(
languageCode: "ENG", languageName: "English", localLanguage: "English"));
final shoutSubCatDataLocal =
value.get('shoutSubCategoryList*${selectedlang!.languageCode!}');
return Container(
color: hexToColor('#E6EDF5'),
height: MediaQuery.of(context).size.height / 3,
//child: shoutC.getShoutSubCategoryById(code: item.categoryCode!).isNotEmpty
child: shoutSubCatDataLocal!.isNotEmpty
? GridView.builder(
shrinkWrap: true,
scrollDirection: Axis.vertical,
padding: EdgeInsets.all(5),
physics: const BouncingScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
mainAxisExtent: 130.0,
crossAxisCount: 3,
),
itemCount: shoutSubCatDataLocal
.where((element) => element.categoryCode == item.categoryCode!)
.length,
itemBuilder: (BuildContext context, int index) {
final subItems = shoutSubCatDataLocal
.where((element) => element.categoryCode == item.categoryCode!)
.toList()[index];
return ReportSubCategoryWidget(
subCategory: subItems,
category: item.categoryName ?? '',
categoryEn: item.categoryName ?? '',
);
},
)
: Container(
child: Center(
child: Text(
'Type not available!',
style: TextStyle(
color: Colors.black,
),
),
),
),
);
})
],
),
),
);
},
),
),
);
}
// bottomNavigationBar: _BottomNavigationSheet(),
)));
}
}
class ReportSubCategoryWidget extends StatelessWidget with Base {
final ShoutSubCategories subCategory;
final String category;
final String categoryEn;
ReportSubCategoryWidget({
super.key,
required this.subCategory,
required this.category,
required this.categoryEn,
});
@override
Widget build(BuildContext context) {
2.delay();
return Container(
padding: EdgeInsets.only(top: 5),
child: Container(
child: InkWell(
onTap: () async {
if (subCategory.isAiValidationApplied! && subCategory.isAiModelUploaded!) {
final file = File('${(await getExternalStorageDirectory())!.path}/${subCategory.id!}.tflite');
final txtFile = File('${(await getExternalStorageDirectory())!.path}/${subCategory.id!}.txt');
//kLog('######### ${await file.exists()}');
if (await file.exists() && await txtFile.exists()) {
//kLog('##### ${subCategory.subcategoryName}');
//kLog(subCategory.id);
await aiModelC.initModel(subCategory.id!);
} else {
if (!await file.exists()) {
await aiModelC.getSubCategoriesAIModel(subCategory.id!);
}
if (!await txtFile.exists()) {
await aiModelC.getSubCategoriesAILabels(subCategory.id!);
}
}
}
shoutC.urgencyLevel.value = subCategory.defaultUrgency!;
if (subCategory.categoryName != 'My Queries') {
shoutC.selectedSubCategory.value = subCategory;
push(ReportIssuePage(
subCategory: subCategory,
category: category,
categoryEn: categoryEn,
));
}
if (subCategory.categoryName == 'My Queries') push(MyQueriesPage(subCategory: subCategory));
if (subCategory.categoryName == 'My Queries')
shoutC.getQueries(subCategory.subcategoryName!, subCategory.subcategoryCode!);
},
child: Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(100)),
border: Border.all(color: hexToColor('#8F94AC')),
),
child: subCategory.subcategoryImage != null
? ImageIcon(
MemoryImage(Utility.uint8ListFromBase64String(subCategory.subcategoryImage!)),
size: 40,
color: subCategory.sucThemeColor != null && subCategory.sucThemeColor != ""
? hexToColor(subCategory.sucThemeColor!)
: AppTheme.appBarColor,
)
: ImageIcon(
AssetImage('assets/images/default_sub_cat_icon.png'),
size: 35,
color: AppTheme.appBarColor,
),
// color: subCategory.sucThemeColor != null ? hexToColor(subCategory.sucThemeColor!) :AppTheme .appBarColor,
// size: 40,
),
Padding(
padding: EdgeInsets.only(left: 5, top: 5, right: 5, bottom: 0),
child: Text(
subCategory.translatedName!,
overflow: TextOverflow.ellipsis,
maxLines: 3,
style: TextStyle(
fontFamily: 'Manrope',
fontSize: 14.0,
height: 1.1,
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
),
// : Text('No Name'),
)
],
),
),
),
),
),
);
}
}
// import 'package:flutter/material.dart';
// import 'package:get/get.dart';
// import 'package:hive_flutter/hive_flutter.dart';
// import 'package:the_citizen_app/src/config/app_theme.dart';
// import 'package:the_citizen_app/src/config/base.dart';
// import 'package:the_citizen_app/src/config/constants.dart';
// import 'package:the_citizen_app/src/helpers/hex_color.dart';
// import 'package:the_citizen_app/src/helpers/k_log.dart';
// import 'package:the_citizen_app/src/helpers/loading.dart';
// import 'package:the_citizen_app/src/helpers/route.dart';
// import 'package:the_citizen_app/src/pages/my_queries_page.dart';
// import '../helpers/k_text.dart';
// import '../hive_models/shout_sub_categories.dart';
// import '../utility/utility.dart';
// import 'report_issue_page.dart';
// class ReportCategoryPage extends StatefulWidget {
// @override
// State<ReportCategoryPage> createState() => _ReportCategoryPageState();
// }
// class _ReportCategoryPageState extends State<ReportCategoryPage> with Base {
// @override
// Widget build(BuildContext context) {
// ScrollController scrollController = ScrollController();
// bool _expansionVisibility = false;
// 5.delay();
// // shoutC.getShoutCategory();
// //shoutC.getShoutSubCategory();
// var constraintData = Hive.box('constraintData');
// var language = constraintData.get(Constants.language);
// return Scaffold(
// body: Obx(
// () => shoutC.shoutCategories.isEmpty
// ? shoutC.isLoading.value
// ? SizedBox(
// height: Get.height / 1.5,
// child: Center(
// child: Loading(),
// ),
// )
// : SizedBox(
// height: Get.height / 1.5,
// child: Center(child: KText(text: 'No data found')),
// )
// : Container(
// color: hexToColor('#F5F9FC'),
// child: Obx(
// () => ListView.builder(
// controller: scrollController,
// key: Key('builder ${shoutC.selectedIndex.toString()}'),
// // key: Key('builder ${selectedIndex.toString()}'),
// padding: EdgeInsets.all(0),
// physics: BouncingScrollPhysics(),
// shrinkWrap: true,
// scrollDirection: Axis.vertical,
// itemCount: shoutC.shoutCategories.length,
// itemBuilder: (BuildContext context, int index) {
// final item = shoutC.shoutCategories[index];
// return InkWell(
// onTap: () {
//
// // shoutC.getShoutSubCategory(item.categoryCode!);
// },
// child: Container(
// decoration: BoxDecoration(
// border: Border(bottom: BorderSide(color: AppTheme.newAppBarTextColor, width: 0.5)),
// color: Colors.white,
// // gradient: LinearGradient(
// // begin: Alignment.topCenter,
// // end: Alignment.bottomCenter,o
// // colors: [
// // Color(0xffF5F9Fc),
// // Color(0xffFFFFFF),
// // Color(0xffFFFFFF),
// // Color(0xffFFFFFF),
// // ],
// // ),
// // boxShadow: [
// // BoxShadow(
// // color: hexToColor('#8DA3AC'),
// // spreadRadius: 3,
// // blurRadius: 5,
// // offset:
// // Offset(0, 3), // changes position of shadow
// // ),
// // ],
// ),
// child: Theme(
// data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
// child: ExpansionTile(
// tilePadding: EdgeInsets.symmetric(vertical: 3, horizontal: 15),
// key: Key(index.toString()),
// iconColor: hexToColor('#8F94AC'),
// textColor: Colors.black,
// backgroundColor: hexToColor('#F5F9FC'),
// childrenPadding: EdgeInsets.zero,
// //initiallyExpanded: false,
// initiallyExpanded: shoutC.selectedIndex.value == index,
// onExpansionChanged: ((newState) {
// kLog(newState);
// if (newState) {
// shoutC.selectedIndex.value = index;
// } else {
// shoutC.selectedIndex.value = index;
// }
// }),
// leading: item.categoryImage != null
// ? ImageIcon(
// MemoryImage(Utility.uint8ListFromBase64String(item.categoryImage!)),
// size: 40,
// color: item.themeColor != null && item.themeColor != ""
// ? hexToColor('${item.themeColor!}')
// : AppTheme.appBarColor,
// )
// : ImageIcon(
// AssetImage('assets/images/shout_logo.png'),
// size: 40,
// color: AppTheme.appBarColor,
// ),
// title: Text(
// item.categoryName != ""
// ? ((language == '0' || language == null) ? '${item.categoryName}' : '${item.categoryName}')
// : 'No Title ',
// style: TextStyle(
// fontFamily: 'Manrope',
// fontSize: 15.0,
// fontWeight: FontWeight.w500,
// ),
// ),
// children: [
// Obx(
// () => Container(
// color: hexToColor('#E6EDF5'),
// height: MediaQuery.of(context).size.height / 3,
// child: shoutC.getShoutSubCategoryById(code: item.categoryCode!).isNotEmpty
// ? Obx(
// () => GridView.builder(
// shrinkWrap: true,
// scrollDirection: Axis.vertical,
// padding: EdgeInsets.all(5),
// physics: const BouncingScrollPhysics(),
// gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
// mainAxisExtent: 130.0,
// crossAxisCount: 3,
// ),
// itemBuilder: (BuildContext context, int index) {
// final subItems = shoutC.getShoutSubCategoryById(code: item.categoryCode!)[index];
// return ReportSubCategoryWidget(
// subCategory: subItems,
// );
// },
// itemCount: shoutC.getShoutSubCategoryById(code: item.categoryCode!).length,
// ),
// )
// : Container(
// child: Center(
// child: Text(
// 'Type not available!',
// style: TextStyle(
// color: Colors.black,
// ),
// ),
// ),
// ),
// ),
// )
// ],
// ),
// ),
// ),
// );
// },
// ),
// ),
// ),
// ),
// // bottomNavigationBar: _BottomNavigationSheet(),
// );
// }
// }
// class ReportSubCategoryWidget extends StatelessWidget with Base {
// final ShoutSubCategories subCategory;
// ReportSubCategoryWidget({
// super.key,
// required this.subCategory,
// });
// @override
// Widget build(BuildContext context) {
// return Container(
// padding: EdgeInsets.only(top: 5),
// child: Container(
// child: InkWell(
// onTap: () {
// kLog(subCategory.attentionEnabled);
// shoutC.urgencyLevel.value = subCategory.defaultUrgency!;
// if (subCategory.categoryName != 'My Queries') {
// shoutC.selectedSubCategory.value = subCategory;
// push(ReportIssuePage(subCategory: subCategory));
// }
// if (subCategory.categoryName == 'My Queries') push(MyQueriesPage(subCategory: subCategory));
// if (subCategory.categoryName == 'My Queries')
// shoutC.getQueries(subCategory.subcategoryName!, subCategory.subcategoryCode!);
// },
// child: Center(
// child: Container(
// child: Column(
// mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Container(
// padding: EdgeInsets.all(15),
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.all(Radius.circular(100)),
// border: Border.all(color: hexToColor('#8F94AC')),
// ),
// child: subCategory.subcategoryImage != null
// ? ImageIcon(
// MemoryImage(Utility.uint8ListFromBase64String(subCategory.subcategoryImage!)),
// size: 40,
// color: subCategory.sucThemeColor != null && subCategory.sucThemeColor != ""
// ? hexToColor(subCategory.sucThemeColor!)
// : AppTheme.appBarColor,
// )
// : ImageIcon(
// AssetImage('assets/images/default_sub_cat_icon.png'),
// size: 40,
// color: AppTheme.appBarColor,
// ),
// // color: subCategory.sucThemeColor != null ? hexToColor(subCategory.sucThemeColor!) :AppTheme .appBarColor,
// // size: 40,
// ),
// Padding(
// padding: EdgeInsets.only(left: 5, top: 5, right: 5, bottom: 0),
// child: Text(
// subCategory.subcategoryName!,
// maxLines: 3,
// overflow: TextOverflow.ellipsis,
// style: TextStyle(
// fontFamily: 'Manrope',
// fontSize: 14.0,
// height: 1.1,
// fontWeight: FontWeight.w500,
// ),
// textAlign: TextAlign.center,
// )
// // : Text('No Name'),
// )
// ],
// ),
// ),
// ),
// ),
// ),
// );
// }
// }
Editor is loading...
Leave a Comment