diff --git a/gorouter b/gorouter new file mode 100644 index 0000000..6b743aa --- /dev/null +++ b/gorouter @@ -0,0 +1,4 @@ +flutter pub add go_router + + +https://pub.dev/documentation/go_router/latest/topics/Get%20started-topic.html \ No newline at end of file diff --git a/lib/mains/gorouter.dart b/lib/mains/gorouter.dart new file mode 100644 index 0000000..d130470 --- /dev/null +++ b/lib/mains/gorouter.dart @@ -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(), + ), + ); +} + + diff --git a/lib/mains/gt.dart b/lib/mains/gt.dart index d4663d9..b086c57 100644 --- a/lib/mains/gt.dart +++ b/lib/mains/gt.dart @@ -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'), + ), ], ) ), - ), - ); + ); } } \ No newline at end of file diff --git a/lib/widgets/map/flutterMap.dart b/lib/widgets/map/flutterMap.dart new file mode 100644 index 0000000..81235a6 --- /dev/null +++ b/lib/widgets/map/flutterMap.dart @@ -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... + // ], + // ), + ], + ); + } +} \ No newline at end of file diff --git a/location b/location new file mode 100644 index 0000000..ab45742 --- /dev/null +++ b/location @@ -0,0 +1 @@ +https://medium.com/@oguzhansergeneser/building-an-efficient-navigation-app-in-flutter-with-google-maps-and-routes-apis-bfb7bf49f1cf \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 2e0e10d..6212f33 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: