90 lines
2.3 KiB
Dart
90 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../widgets/flood_station_list_view.dart';
|
|
import '../services/flood_station_provider.dart';
|
|
import '../widgets/loading_notifier.dart';
|
|
import '../widgets/station_filter.dart';
|
|
import 'flood_station_page.dart';
|
|
|
|
class LandingPage extends StatefulWidget {
|
|
const LandingPage({super.key});
|
|
|
|
static const routeName = '/';
|
|
|
|
@override
|
|
State<LandingPage> createState() => _LandingPageState();
|
|
}
|
|
|
|
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());
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
floodStationProvider = context.watch<FloodStationProvider>();
|
|
return Scaffold(
|
|
body: Column(
|
|
children: [
|
|
StationFilter(
|
|
onEditingComplete: (filterText) {},
|
|
),
|
|
Expanded(
|
|
child: FloodStationListView(
|
|
stations: floodStationProvider.allStations,
|
|
onItemTapped: (station) {
|
|
floodStationProvider.selectedStation = station;
|
|
Navigator.of(context).pushNamed(FloodStationPage.routeName);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> showLoadingNotifier({
|
|
required BuildContext context,
|
|
required String message,
|
|
}) async {
|
|
OverlayState? overlayState = Overlay.of(context);
|
|
_overlayEntry = OverlayEntry(
|
|
builder: (c) {
|
|
return Positioned(
|
|
bottom: 16,
|
|
left: 0,
|
|
right: 0,
|
|
child: Center(
|
|
child: LoadingNotifier(
|
|
message: 'Loading',
|
|
onDismissed: () => removeLoadingNotifier(),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
overlayState.insert(_overlayEntry!);
|
|
overlayState.setState(() {});
|
|
}
|
|
|
|
void removeLoadingNotifier() {
|
|
if (_overlayEntry != null) {
|
|
_overlayEntry?.remove();
|
|
_overlayEntry = null;
|
|
}
|
|
}
|
|
}
|