added loading indicator for mapview
This commit is contained in:
		@@ -2,11 +2,18 @@ import 'package:flutter/cupertino.dart';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class MapState extends ChangeNotifier {
 | 
					class MapState extends ChangeNotifier {
 | 
				
			||||||
  bool _isLocationLock = false;
 | 
					  bool _isLocationLock = false;
 | 
				
			||||||
 | 
					  bool _isCurrentlyFetchin = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool get followLocation => _isLocationLock;
 | 
					  bool get followLocation => _isLocationLock;
 | 
				
			||||||
 | 
					  bool get isCurrentlyFetching => _isCurrentlyFetchin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  toggleLocationLock() {
 | 
					  toggleLocationLock() {
 | 
				
			||||||
    _isLocationLock = !_isLocationLock;
 | 
					    _isLocationLock = !_isLocationLock;
 | 
				
			||||||
    notifyListeners();
 | 
					    notifyListeners();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  set setNetworkActivity(bool active) {
 | 
				
			||||||
 | 
					    _isCurrentlyFetchin = active;
 | 
				
			||||||
 | 
					    notifyListeners();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										23
									
								
								lib/util/loadingContainer.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								lib/util/loadingContainer.dart
									
									
									
									
									
										Normal 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),
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,10 +1,12 @@
 | 
				
			|||||||
import 'package:app/extensions/obtainProviderExtension.dart';
 | 
					import 'package:app/extensions/obtainProviderExtension.dart';
 | 
				
			||||||
import 'package:app/state/mapState.dart';
 | 
					import 'package:app/state/mapState.dart';
 | 
				
			||||||
 | 
					import 'package:app/util/loadingContainer.dart';
 | 
				
			||||||
import 'package:app/util/watchState.dart';
 | 
					import 'package:app/util/watchState.dart';
 | 
				
			||||||
import 'package:app/view/appInfo.dart';
 | 
					import 'package:app/view/appInfo.dart';
 | 
				
			||||||
import 'package:app/view/status.dart';
 | 
					import 'package:app/view/status.dart';
 | 
				
			||||||
import 'package:app/view/map.dart';
 | 
					import 'package:app/view/map.dart';
 | 
				
			||||||
import 'package:flutter/material.dart';
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
 | 
					import 'package:provider/provider.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class HomeView extends StatefulWidget {
 | 
					class HomeView extends StatefulWidget {
 | 
				
			||||||
  const HomeView({super.key});
 | 
					  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)),
 | 
					        child: WatchState<MapState>((context, state) => Icon(state.followLocation ? Icons.my_location : Icons.location_disabled)),
 | 
				
			||||||
        onPressed: () => context.obtainState<MapState>().toggleLocationLock(),
 | 
					        onPressed: () => context.obtainState<MapState>().toggleLocationLock(),
 | 
				
			||||||
      ),
 | 
					      ),
 | 
				
			||||||
      body: const Column(
 | 
					      body: Column(
 | 
				
			||||||
        children: [
 | 
					        children: [
 | 
				
			||||||
          SizedBox(
 | 
					          const SizedBox(
 | 
				
			||||||
            height: 100,
 | 
					            height: 100,
 | 
				
			||||||
            child: StatusView(),
 | 
					            child: StatusView(),
 | 
				
			||||||
          ),
 | 
					          ),
 | 
				
			||||||
          Expanded(
 | 
					          Expanded(
 | 
				
			||||||
            child: MapView(),
 | 
					            child: Consumer<MapState>(
 | 
				
			||||||
 | 
					              builder: (context, state, child) {
 | 
				
			||||||
 | 
					                return LoadingContainer(
 | 
				
			||||||
 | 
					                  loading: child == null,
 | 
				
			||||||
 | 
					                  fetching: state.isCurrentlyFetching,
 | 
				
			||||||
 | 
					                  child: const MapView(),
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					              child: const MapView(),
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
      ),
 | 
					      ),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user