Fixed bug - Loading Indicator now functions correctly
This commit is contained in:
@@ -18,20 +18,8 @@ class LandingPage extends StatefulWidget {
|
||||
|
||||
class _LandingPageState extends State<LandingPage> {
|
||||
late FloodStationProvider floodStationProvider;
|
||||
bool _isLoading = false;
|
||||
OverlayEntry? _overlayEntry;
|
||||
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_isLoading = true;
|
||||
showLoadingNotifier(context: context, message: 'Loading');
|
||||
floodStationProvider
|
||||
.loadAllStations()
|
||||
.whenComplete(() => removeLoadingNotifier());
|
||||
});
|
||||
}
|
||||
int loadingTimes = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -40,26 +28,67 @@ class _LandingPageState extends State<LandingPage> {
|
||||
body: Column(
|
||||
children: [
|
||||
StationFilter(
|
||||
onEditingComplete: (filterText) {},
|
||||
),
|
||||
Expanded(
|
||||
child: FloodStationListView(
|
||||
stations: floodStationProvider.allStations,
|
||||
onItemTapped: (station) {
|
||||
floodStationProvider.selectedStation = station;
|
||||
Navigator.of(context).pushNamed(FloodStationPage.routeName);
|
||||
},
|
||||
),
|
||||
onChanged: (filterText) {
|
||||
if (filterText.isEmpty) {
|
||||
floodStationProvider.filtered = false;
|
||||
setState(() {});
|
||||
return;
|
||||
}
|
||||
showLoadingNotifier(context: context, message: 'Loading');
|
||||
floodStationProvider.loadFilteredStations(filterText);
|
||||
floodStationProvider.filteredStationsFuture
|
||||
?.then((_) => removeLoadingNotifier());
|
||||
floodStationProvider.filtered = true;
|
||||
},
|
||||
),
|
||||
_shouldShowList()
|
||||
? Expanded(
|
||||
child: FloodStationListView(
|
||||
stations: floodStationProvider.filtered
|
||||
? floodStationProvider.filteredStations
|
||||
: floodStationProvider.allStations,
|
||||
onItemTapped: (station) {
|
||||
floodStationProvider.selectedStation = station;
|
||||
Navigator.of(context)
|
||||
.pushNamed(FloodStationPage.routeName);
|
||||
},
|
||||
),
|
||||
)
|
||||
: Expanded(
|
||||
child: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
showLoadingNotifier(
|
||||
context: context, message: 'Loading');
|
||||
floodStationProvider
|
||||
.loadAllStations()
|
||||
.whenComplete(() => removeLoadingNotifier());
|
||||
},
|
||||
child: Text('Load all Stations'),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _shouldShowList() {
|
||||
if (!floodStationProvider.filtered &&
|
||||
floodStationProvider.allStations.isNotEmpty) {
|
||||
return true;
|
||||
}
|
||||
if (floodStationProvider.filtered) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> showLoadingNotifier({
|
||||
required BuildContext context,
|
||||
required String message,
|
||||
}) async {
|
||||
if (_overlayEntry != null) return;
|
||||
OverlayState? overlayState = Overlay.of(context);
|
||||
_overlayEntry = OverlayEntry(
|
||||
builder: (c) {
|
||||
@@ -70,7 +99,10 @@ class _LandingPageState extends State<LandingPage> {
|
||||
child: Center(
|
||||
child: LoadingNotifier(
|
||||
message: 'Loading',
|
||||
onDismissed: () => removeLoadingNotifier(),
|
||||
onDismissed: () {
|
||||
floodStationProvider.cancelFilterLoading();
|
||||
removeLoadingNotifier();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user