osm_flutter_hooks 1.3.0 copy "osm_flutter_hooks: ^1.3.0" to clipboard
osm_flutter_hooks: ^1.3.0 copied to clipboard

this Package extension to add support manage hook state with osm_flutter

example/lib/main.dart

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);
      },
    );
    useMapListener(
        controller: controller,
        onSingleTap: (p) async {
          await controller.addMarker(p);
        });
    return OSMFlutter(
      controller: controller,
      initZoom: 10,
      markerOption: MarkerOption(
        defaultMarker: const MarkerIcon(
          icon: Icon(
            Icons.person_pin_circle,
            color: Colors.blue,
            size: 56,
          ),
        ),
      ),
      userLocationMarker: UserLocationMaker(
        personMarker: const MarkerIcon(
          icon: Icon(
            Icons.person,
            size: 48,
            color: Colors.red,
          ),
        ),
        directionArrowMarker: const MarkerIcon(
          icon: Icon(Icons.person),
        ),
      ),
      trackMyPosition: true,
    );
  }
}
9
likes
0
pub points
78%
popularity

Publisher

unverified uploader

this Package extension to add support manage hook state with osm_flutter

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_hooks, flutter_osm_plugin

More

Packages that depend on osm_flutter_hooks