Misc + clean code logic future for configurations and sections
This commit is contained in:
parent
9c5ae56549
commit
4946247812
@ -43,11 +43,14 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
List<String?> alreadyDownloaded = [];
|
List<String?> alreadyDownloaded = [];
|
||||||
late VisitAppContext visitAppContext;
|
late VisitAppContext visitAppContext;
|
||||||
|
|
||||||
|
late Future<List<ConfigurationDTO>?> _futureConfigurations;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
super.initState();
|
super.initState();
|
||||||
|
final appContext = Provider.of<AppContext>(context, listen: false);
|
||||||
|
_futureConfigurations = getConfigurationsCall(appContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -59,7 +62,7 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
extendBody: true,
|
extendBody: true,
|
||||||
body: FutureBuilder(
|
body: FutureBuilder(
|
||||||
future: getConfigurationsCall(visitAppContext.clientAPI, appContext),
|
future: _futureConfigurations,//getConfigurationsCall(visitAppContext.clientAPI, appContext),
|
||||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
configurations = List<ConfigurationDTO>.from(snapshot.data).where((configuration) => configuration.isMobile!).toList();
|
configurations = List<ConfigurationDTO>.from(snapshot.data).where((configuration) => configuration.isMobile!).toList();
|
||||||
@ -287,9 +290,9 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
return Text(TranslationHelper.getFromLocale("noData", appContext.getContext()));
|
return Text(TranslationHelper.getFromLocale("noData", appContext.getContext()));
|
||||||
} else {
|
} else {
|
||||||
return Center(
|
return Center(
|
||||||
child: Container(
|
child: SizedBox(
|
||||||
height: size.height * 0.15,
|
height: size.height * 0.15,
|
||||||
child: LoadingCommon()
|
child: const LoadingCommon()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -309,7 +312,7 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
width: size.width,
|
width: size.width,
|
||||||
height: size.height,
|
height: size.height,
|
||||||
child: FutureBuilder(
|
child: FutureBuilder(
|
||||||
future: getConfigurationsCall(visitAppContext.clientAPI, appContext),
|
future: getConfigurationsCall(appContext),
|
||||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
configurations = List<ConfigurationDTO>.from(snapshot.data).where((configuration) => configuration.isMobile!).toList();
|
configurations = List<ConfigurationDTO>.from(snapshot.data).where((configuration) => configuration.isMobile!).toList();
|
||||||
@ -392,7 +395,7 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<ConfigurationDTO>?> getConfigurationsCall(Client client, AppContext appContext) async {
|
Future<List<ConfigurationDTO>?> getConfigurationsCall(AppContext appContext) async {
|
||||||
bool isOnline = await hasNetwork();
|
bool isOnline = await hasNetwork();
|
||||||
VisitAppContext visitAppContext = appContext.getContext();
|
VisitAppContext visitAppContext = appContext.getContext();
|
||||||
|
|
||||||
@ -424,7 +427,7 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(visitAppContext.beaconSections == null) {
|
if(visitAppContext.beaconSections == null) {
|
||||||
List<SectionDTO>? sections = await ApiService.getAllBeacons(client, visitAppContext.instanceId!);
|
List<SectionDTO>? sections = await ApiService.getAllBeacons(visitAppContext.clientAPI, visitAppContext.instanceId!);
|
||||||
if(sections != null && sections.isNotEmpty) {
|
if(sections != null && sections.isNotEmpty) {
|
||||||
List<BeaconSection> beaconSections = sections.map((e) => BeaconSection(minorBeaconId: e.beaconId, orderInConfig: e.order, configurationId: e.configurationId, sectionId: e.id, sectionType: e.type)).toList();
|
List<BeaconSection> beaconSections = sections.map((e) => BeaconSection(minorBeaconId: e.beaconId, orderInConfig: e.order, configurationId: e.configurationId, sectionId: e.id, sectionType: e.type)).toList();
|
||||||
visitAppContext.beaconSections = beaconSections;
|
visitAppContext.beaconSections = beaconSections;
|
||||||
@ -448,6 +451,6 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await ApiService.getConfigurations(client, visitAppContext);
|
return await ApiService.getConfigurations(visitAppContext.clientAPI, visitAppContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,12 +31,20 @@ class _BodyState extends State<Body> {
|
|||||||
late List<SectionDTO> sections;
|
late List<SectionDTO> sections;
|
||||||
late List<SectionDTO> _allSections;
|
late List<SectionDTO> _allSections;
|
||||||
late List<dynamic> rawSections;
|
late List<dynamic> rawSections;
|
||||||
List<SectionDTO> sectionsToDisplay = [];
|
|
||||||
String? searchValue;
|
String? searchValue;
|
||||||
int? searchNumberValue;
|
int? searchNumberValue;
|
||||||
|
|
||||||
final ValueNotifier<List<SectionDTO>> filteredSections = ValueNotifier([]);
|
final ValueNotifier<List<SectionDTO>> filteredSections = ValueNotifier([]);
|
||||||
|
|
||||||
|
late Future<List<SectionDTO>> _futureSections;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
final appContext = Provider.of<AppContext>(context, listen: false);
|
||||||
|
_futureSections = getSections(appContext);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final appContext = Provider.of<AppContext>(context);
|
final appContext = Provider.of<AppContext>(context);
|
||||||
@ -88,9 +96,10 @@ class _BodyState extends State<Body> {
|
|||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
//setState(() {
|
//setState(() {
|
||||||
|
/**/
|
||||||
|
Navigator.of(context).pop();
|
||||||
visitAppContext.configuration = null;
|
visitAppContext.configuration = null;
|
||||||
visitAppContext.isScanningBeacons = false;
|
visitAppContext.isScanningBeacons = false;
|
||||||
Navigator.of(context).pop();
|
|
||||||
/*Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(
|
/*Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(
|
||||||
builder: (context) => const HomePage3(),
|
builder: (context) => const HomePage3(),
|
||||||
),(route) => false);*/
|
),(route) => false);*/
|
||||||
@ -114,13 +123,6 @@ class _BodyState extends State<Body> {
|
|||||||
SearchBox(onChanged: (value) {
|
SearchBox(onChanged: (value) {
|
||||||
searchValue = value?.trim();
|
searchValue = value?.trim();
|
||||||
applyFilters(visitAppContext);
|
applyFilters(visitAppContext);
|
||||||
/*setState(() {
|
|
||||||
if(value != null && value != "") {
|
|
||||||
searchValue = value;
|
|
||||||
} else {
|
|
||||||
searchValue = null;
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
}),
|
}),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SearchNumberBox(onChanged: (value) {
|
child: SearchNumberBox(onChanged: (value) {
|
||||||
@ -132,15 +134,6 @@ class _BodyState extends State<Body> {
|
|||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
applyFilters(visitAppContext);
|
applyFilters(visitAppContext);
|
||||||
}
|
}
|
||||||
/*setState(() {
|
|
||||||
if(value != null && value != "") {
|
|
||||||
searchNumberValue = int.parse(value);
|
|
||||||
} else {
|
|
||||||
searchNumberValue = null;
|
|
||||||
FocusScope.of(context).unfocus();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}*/
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -169,7 +162,7 @@ class _BodyState extends State<Body> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
FutureBuilder(
|
FutureBuilder(
|
||||||
future: getSections(appContext),
|
future: _futureSections,
|
||||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
/*print("SECTIONTODISPA");
|
/*print("SECTIONTODISPA");
|
||||||
@ -179,8 +172,9 @@ class _BodyState extends State<Body> {
|
|||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
if(!widget.configuration.isOffline!) {
|
if(!widget.configuration.isOffline!) {
|
||||||
// Force refresh if online
|
setState(() {
|
||||||
setState(() {});
|
_futureSections = getSections(appContext);
|
||||||
|
});
|
||||||
} },
|
} },
|
||||||
child: ValueListenableBuilder<List<SectionDTO>>(
|
child: ValueListenableBuilder<List<SectionDTO>>(
|
||||||
valueListenable: filteredSections,
|
valueListenable: filteredSections,
|
||||||
@ -231,7 +225,7 @@ class _BodyState extends State<Body> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSections(AppContext appContext) async {
|
Future<List<SectionDTO>> getSections(AppContext appContext) async {
|
||||||
VisitAppContext visitAppContext = appContext.getContext();
|
VisitAppContext visitAppContext = appContext.getContext();
|
||||||
if(widget.configuration.isOffline!)
|
if(widget.configuration.isOffline!)
|
||||||
{
|
{
|
||||||
@ -255,26 +249,11 @@ class _BodyState extends State<Body> {
|
|||||||
|
|
||||||
sections = sections.where((s) => s.configurationId == widget.configuration.id!).toList();
|
sections = sections.where((s) => s.configurationId == widget.configuration.id!).toList();
|
||||||
sections.sort((a,b) => a.order!.compareTo(b.order!));
|
sections.sort((a,b) => a.order!.compareTo(b.order!));
|
||||||
//sectionsToDisplay = sections;
|
|
||||||
try {
|
|
||||||
_allSections = sections;
|
_allSections = sections;
|
||||||
|
|
||||||
//visitAppContext.currentSections = sectionsToDisplay;
|
|
||||||
|
|
||||||
applyFilters(visitAppContext);
|
applyFilters(visitAppContext);
|
||||||
} catch(e) {
|
|
||||||
print(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*if(searchValue != '' && searchValue != null) {
|
return _allSections;
|
||||||
sectionsToDisplay = sections.where((s) => removeDiacritics(TranslationHelper.get(s.title, appContext.getContext()).toLowerCase()).contains(removeDiacritics(searchValue.toString().toLowerCase()))).toList();
|
|
||||||
} else {
|
|
||||||
if(searchNumberValue != null) {
|
|
||||||
sectionsToDisplay = sections.where((s) => s.order!+1 == searchNumberValue).toList();
|
|
||||||
} else {
|
|
||||||
sectionsToDisplay = sections;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyFilters(VisitAppContext visitAppContext) {
|
void applyFilters(VisitAppContext visitAppContext) {
|
||||||
|
|||||||
@ -341,7 +341,7 @@ class _VisitPageState extends State<VisitPage> with WidgetsBindingObserver {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: false,
|
canPop: true,
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
/*appBar: CustomAppBar(
|
/*appBar: CustomAppBar(
|
||||||
title: TranslationHelper.get(configuration!.title, visitAppContext),
|
title: TranslationHelper.get(configuration!.title, visitAppContext),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user