osm_flutter_hooks 1.1.1 osm_flutter_hooks: ^1.1.1 copied to clipboard
this Package extension to add support manage hook state with osm_flutter
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_osm_plugin/flutter_osm_plugin.dart';
import 'package:osm_flutter_hooks/osm_flutter_hooks.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: const Center(
child: SimpleOSM(),
),
);
}
}
class SimpleOSM extends HookWidget {
const SimpleOSM({super.key});
@override
Widget build(BuildContext context) {
final controller = useMapController(
initMapWithUserPosition: true
);
useMapIsReady(
controller: controller,
mapIsReady: () async {
await controller.setZoom(zoomLevel: 15);
},
);
return OSMFlutter(
controller: controller,
initZoom: 10,
markerOption: MarkerOption(
defaultMarker: const MarkerIcon(
icon: Icon(
Icons.person_pin_circle,
color: Colors.blue,
size: 56,
),
),
),
trackMyPosition: true,
);
}
}