A little about router, a little about map.
This commit is contained in:
parent
8e58ae5503
commit
8f350a5aec
4
gorouter
Normal file
4
gorouter
Normal file
@ -0,0 +1,4 @@
|
||||
flutter pub add go_router
|
||||
|
||||
|
||||
https://pub.dev/documentation/go_router/latest/topics/Get%20started-topic.html
|
||||
50
lib/mains/gorouter.dart
Normal file
50
lib/mains/gorouter.dart
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../widgets/map/flutterMap.dart';
|
||||
import 'gt.dart';
|
||||
|
||||
final _router = GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => const MyApp(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'map2',
|
||||
builder: (context, state) => const MyMAP(),
|
||||
)
|
||||
]
|
||||
),
|
||||
GoRoute(
|
||||
path: '/map',
|
||||
builder: (context, state) => const MyMAP(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
class GoRouterMain extends StatelessWidget {
|
||||
const GoRouterMain({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp.router(
|
||||
routerConfig: _router,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(
|
||||
// For widgets to be able to read providers, we need to wrap the entire
|
||||
// application in a "ProviderScope" widget.
|
||||
// This is where the state of our providers will be stored.
|
||||
const ProviderScope(
|
||||
child: GoRouterMain(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,8 @@ import 'package:riverpod_flutter_tuts/widgets/notifier/counter_widget.dart';
|
||||
import '../widgets/consumer/random.dart';
|
||||
import '../widgets/notifier/random_widget.dart';
|
||||
import '../widgets/simples/random.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
|
||||
part 'gt.g.dart';
|
||||
|
||||
@ -35,8 +37,7 @@ class MyApp extends ConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final String value = ref.watch(helloWorldProvider);
|
||||
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Example')),
|
||||
body: Center(
|
||||
child: Column(
|
||||
@ -47,11 +48,18 @@ class MyApp extends ConsumerWidget {
|
||||
const Expanded(child: Random2Widget()),
|
||||
const Expanded(child: CounterWidget()),
|
||||
const Expanded(child: Random3Widget()),
|
||||
ElevatedButton(
|
||||
onPressed: () => context.go('/map'),
|
||||
child: const Text('map'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => context.push('/map2'),
|
||||
child: const Text('map2'),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
52
lib/widgets/map/flutterMap.dart
Normal file
52
lib/widgets/map/flutterMap.dart
Normal file
@ -0,0 +1,52 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_map_cancellable_tile_provider/flutter_map_cancellable_tile_provider.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
|
||||
|
||||
class MyMAP extends StatelessWidget {
|
||||
final LatLng initCenter;
|
||||
final double initZoom;
|
||||
const MyMAP({super.key, this.initCenter = const LatLng(51.509364, -0.128928), this.initZoom = 15});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
TileProvider? tileProvider = null;
|
||||
if (kIsWeb) {
|
||||
tileProvider = CancellableNetworkTileProvider();
|
||||
}
|
||||
return FlutterMap(
|
||||
options: MapOptions(
|
||||
initialCenter: initCenter,
|
||||
// Center the map over London
|
||||
initialZoom: initZoom,
|
||||
maxZoom:20,
|
||||
minZoom: 10,
|
||||
),
|
||||
children: [
|
||||
|
||||
|
||||
TileLayer( // Display map tiles from any source
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
tileProvider: tileProvider,
|
||||
// OSMF's Tile Server
|
||||
userAgentPackageName: 'com.example.app',
|
||||
maxNativeZoom: 19, // Scale tiles when the server doesn't support higher zoom levels
|
||||
// And many more recommended properties!
|
||||
),
|
||||
// RichAttributionWidget( // Include a stylish prebuilt attribution widget that meets all requirments
|
||||
// attributions: [
|
||||
// TextSourceAttribution(
|
||||
// 'OpenStreetMap contributors',
|
||||
// onTap: () =>
|
||||
// launchUrl(Uri.parse(
|
||||
// 'https://openstreetmap.org/copyright')), // (external)
|
||||
// ),
|
||||
// // Also add images...
|
||||
// ],
|
||||
// ),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
1
location
Normal file
1
location
Normal file
@ -0,0 +1 @@
|
||||
https://medium.com/@oguzhansergeneser/building-an-efficient-navigation-app-in-flutter-with-google-maps-and-routes-apis-bfb7bf49f1cf
|
||||
@ -40,6 +40,11 @@ dependencies:
|
||||
freezed_annotation: ^2.4.3
|
||||
json_annotation: ^4.9.0
|
||||
http: ^1.2.1
|
||||
go_router: ^14.2.7
|
||||
flutter_map: ^7.0.2
|
||||
latlong2: ^0.9.1
|
||||
url_launcher: ^6.3.0
|
||||
flutter_map_cancellable_tile_provider: ^3.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user