diff --git a/lib/state/mapState.dart b/lib/state/mapState.dart index 510c19a..6383c63 100644 --- a/lib/state/mapState.dart +++ b/lib/state/mapState.dart @@ -2,11 +2,18 @@ import 'package:flutter/cupertino.dart'; class MapState extends ChangeNotifier { bool _isLocationLock = false; + bool _isCurrentlyFetchin = true; bool get followLocation => _isLocationLock; + bool get isCurrentlyFetching => _isCurrentlyFetchin; toggleLocationLock() { _isLocationLock = !_isLocationLock; notifyListeners(); } + + set setNetworkActivity(bool active) { + _isCurrentlyFetchin = active; + notifyListeners(); + } } \ No newline at end of file diff --git a/lib/util/loadingContainer.dart b/lib/util/loadingContainer.dart new file mode 100644 index 0000000..cc60908 --- /dev/null +++ b/lib/util/loadingContainer.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; + +class LoadingContainer extends StatelessWidget { + final bool loading; + final bool fetching; + final Widget child; + const LoadingContainer({required this.loading, required this.fetching, required this.child, super.key}); + + @override + Widget build(BuildContext context) { + if(loading) { + return const Center(child: CircularProgressIndicator()); + } + + return Column( + mainAxisSize: MainAxisSize.max, + children: [ + if(fetching) const LinearProgressIndicator(), + Expanded(child: child), + ], + ); + } +} diff --git a/lib/view/home.dart b/lib/view/home.dart index a38b1b3..49e4da2 100644 --- a/lib/view/home.dart +++ b/lib/view/home.dart @@ -1,10 +1,12 @@ import 'package:app/extensions/obtainProviderExtension.dart'; import 'package:app/state/mapState.dart'; +import 'package:app/util/loadingContainer.dart'; import 'package:app/util/watchState.dart'; import 'package:app/view/appInfo.dart'; import 'package:app/view/status.dart'; import 'package:app/view/map.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; class HomeView extends StatefulWidget { const HomeView({super.key}); @@ -42,14 +44,23 @@ class _HomePageState extends State<HomeView> { child: WatchState<MapState>((context, state) => Icon(state.followLocation ? Icons.my_location : Icons.location_disabled)), onPressed: () => context.obtainState<MapState>().toggleLocationLock(), ), - body: const Column( + body: Column( children: [ - SizedBox( + const SizedBox( height: 100, child: StatusView(), ), Expanded( - child: MapView(), + child: Consumer<MapState>( + builder: (context, state, child) { + return LoadingContainer( + loading: child == null, + fetching: state.isCurrentlyFetching, + child: const MapView(), + ); + }, + child: const MapView(), + ), ) ], ),