added loading indicator for mapview

This commit is contained in:
Elias Müller 2024-03-26 21:41:42 +01:00
parent 10b0c59c3f
commit 7ce510e690
3 changed files with 44 additions and 3 deletions

View File

@ -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();
}
}

View File

@ -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),
],
);
}
}

View File

@ -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(),
),
)
],
),