map_flutter 0.0.1 copy "map_flutter: ^0.0.1" to clipboard
map_flutter: ^0.0.1 copied to clipboard

A Flutter package for interactive maps with trip planning, routing, dynamic markers and filtering. Supports Google Maps & OpenStreetMap (OSM) via OpenRouteService.

example/lib/main.dart

import 'dart:io' show Platform, HttpOverrides;

import 'package:example/models/driver_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:map_flutter/map_flutter.dart';
import 'package:url_launcher/url_launcher.dart';

import 'help/help.dart';

void main() {
  HttpOverrides.global = MyHttpOverrides();
  runApp(ProviderScope(child: MyApp()));
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: 'Flutter Map Package', home: MapScreen());
  }
}

class MapScreen extends ConsumerStatefulWidget {
  const MapScreen({super.key});

  @override
  ConsumerState<MapScreen> createState() => _StateMapScreen();
}

class _StateMapScreen extends ConsumerState<MapScreen> {
  final String _apiKey = "YOUR_API_KEY";
  final String _userAgent = "AppClient/2.0 (contact@client.com)";

  //Timer? _timer;
  @override
  void initState() {
    super.initState();

    /*WidgetsBinding.instance.addPostFrameCallback((_) async {
      _showBottomSheet(context);
    });*/
    /*_timer = Timer.periodic(Duration(seconds: 1), (timer) {
      _updateDriversLocation();
    });*/
  }

  /*void _updateDriversLocation() {
    setState(() {
      for (var driver in driverList) {
        driver.latitude += 0.0005 * (Random().nextDouble() - 0.5); // Variation aléatoire
        driver.longitude += 0.0005 * (Random().nextDouble() - 0.5); // Variation aléatoire
      }
    });
  }*/

  @override
  void dispose() {
    //_timer?.cancel();
    super.dispose();
  }

  Future<bool> _cancelRequest() async {
    final success = false;
    if (success) {
    }
    return success;
  }

  Future<void> _callNumber() async {
    final Uri url = Uri(scheme: 'tel', path: '+22898797353');
    if (await canLaunchUrl(url)) {
      await launchUrl(
          url, mode: LaunchMode.externalApplication);
    } else {
      throw 'Impossible de lancer $url';
    }
  }

  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    final vehicleSelected = FlutterMapPackage(ref).getVehicleSelected();
    final isForSomeoneElse = FlutterMapPackage(ref).getIsForSomeoneElse();
    final flutterMapPackage = FlutterMapPackage(ref);
    return Scaffold(
      resizeToAvoidBottomInset: false,
      //appBar: AppBar(title: Text('Google Maps Package')),
      /*bottomSheet: SizedBox(
        height: size.height * 0.5,
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[

            ],
          ),
        ),
      ),*/
      body: Stack(
        children: [
          Positioned.fill(
            child: MapWidget(
              //setPickOnPosition: LatLng(6.1319, 1.2228),
              onFetchMapMarkers: () async {
                return driverList.map((data) => MapMarkerModel(
                    id: data.id,
                    legendName: 'Chauffeurs',
                    path: 'https://static.vecteezy.com/system/resources/previews/016/617/627/non_2x/the-taxi-car-is-yellow-free-png.png',
                    latitude: data.latitude,
                    longitude: data.longitude,
                    title: data.name,
                    info: data,
                    firstInfo: data.carPlate,
                    secondInfo: 'Taxi',
                    thirdInfo: data.carBrand,
                    fourthInfo: data.carModel,
                    infoImageUrl: data.imageUrl
                )).toList();
              },
              apiKey: _apiKey,
              userAgent: _userAgent,
              mapApiProvider: MapApiProvider.openStreetMap,
              mapTypeProvider: MapTypeProvider.trip,
              mapRequestType: MapRequestType.transport,
              showInfoWindowButtonWidget: true,
              vehicleSelected: vehicleSelected,
              infoWindowButtonWidget: (info, pickupLocation, waypoints, mapRouteInfo, mapTripForSomeoneElse, mapDeliveryPackage, dropOffLocation){
                return ElevatedButton(
                  onPressed: () {

                  },
                  style: ElevatedButton.styleFrom(
                    backgroundColor: Colors.green,
                    padding: const EdgeInsets.symmetric(horizontal: 26, vertical: 10),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(12),
                    ),
                  ),
                  child: Text(
                    'Commander',
                    style: const TextStyle(
                      fontSize: 18,
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                );
              },
            ),
          ),
          DraggableWidget(
            /*vehiclesFetchWidget: (pickupLocation, waypoints, dropOffLocation) {
              return SizedBox(
                width: size.width,
                child: Text('Widget pour afficher les voitures ${pickupLocation.address} ${dropOffLocation.address}'),
              );
            },*/
            onFetchVehicles: (pickupLocation, waypoints,  mapRouteInfo, mapDeliveryPackage, dropOffLocation) async{
              //return [];
              return [
                MapVehicleModel(name: 'Berline', imageUrl: 'https://img.freepik.com/free-psd/yellow-isolated-car_23-2151852890.jpg?t=st=1741359752~exp=1741363352~hmac=9b41b436c4ab81e224eaf97b6faf5986fb52d98e96f50a3f76370122cc708482&w=2000', price: 2000, seats: 4),
                MapVehicleModel(name: 'SUV', imageUrl: 'https://img.freepik.com/free-psd/yellow-isolated-car_23-2151852890.jpg?t=st=1741359752~exp=1741363352~hmac=9b41b436c4ab81e224eaf97b6faf5986fb52d98e96f50a3f76370122cc708482&w=2000', price: 3500, seats: 6),
                MapVehicleModel(name: 'Moto', imageUrl: 'https://img.freepik.com/free-psd/yellow-isolated-car_23-2151852890.jpg?t=st=1741359752~exp=1741363352~hmac=9b41b436c4ab81e224eaf97b6faf5986fb52d98e96f50a3f76370122cc708482&w=2000', price: 1000, seats: 1),
              ];
            },
            showOnViewItemButton: true,
            mapItems: [
              MapItemModel(name: 'Berline', imageUrl: 'https://img.freepik.com/free-psd/yellow-isolated-car_23-2151852890.jpg?t=st=1741359752~exp=1741363352~hmac=9b41b436c4ab81e224eaf97b6faf5986fb52d98e96f50a3f76370122cc708482&w=2000', description: 'https://img.freepik.com/free-psd/yellow-isolated-car_23-2151852890.jpg?t=st=1741359752~exp=1741363352~hmac=9b41b436c4ab81e224eaf97b6faf5986fb52d98e96f50a3f76370122cc708482&w=2000', type: 'pharmacie', rating: 0, location: LatLng(6.1725, 1.2313)),
              MapItemModel(name: 'SUV', imageUrl: 'https://img.freepik.com/free-psd/yellow-isolated-car_23-2151852890.jpg?t=st=1741359752~exp=1741363352~hmac=9b41b436c4ab81e224eaf97b6faf5986fb52d98e96f50a3f76370122cc708482&w=2000', description: 'https://img.freepik.com/free-psd/yellow-isolated-car_23-2151852890.jpg?t=st=1741359752~exp=1741363352~hmac=9b41b436c4ab81e224eaf97b6faf5986fb52d98e96f50a3f76370122cc708482&w=2000', type: 'pharmacie'),
              MapItemModel(name: 'Moto', imageUrl: 'https://img.freepik.com/free-psd/yellow-isolated-car_23-2151852890.jpg?t=st=1741359752~exp=1741363352~hmac=9b41b436c4ab81e224eaf97b6faf5986fb52d98e96f50a3f76370122cc708482&w=2000', description: 'https://img.freepik.com/free-psd/yellow-isolated-car_23-2151852890.jpg?t=st=1741359752~exp=1741363352~hmac=9b41b436c4ab81e224eaf97b6faf5986fb52d98e96f50a3f76370122cc708482&w=2000', type: 'université', location: LatLng(6.1825, 1.2313)),
            ],
            onBack: (){
              Navigator.of(context).pop();
            },
            allowedBookingSomeoneElse: true,
            tripStatus: MapTripStatusModel(
                currency: 'XOF',
                status: 'driver_assigned', //driver_assigned searching_driver driver_arrived in_progress
                distance: 13.85,
                estimatedPrice: 3234.8,
                pickup: MapAddressListModel(
                    address: '46H9+RVC, Lomé, Togo',
                    latLng: LatLng(6.129556704157772, 1.2196500599384308)
                ),
                dropoff: MapAddressListModel(
                    address: '587G+PG6, Lomé, Togo',
                    latLng: LatLng(6.164285615611506, 1.3262742385268211)
                ),
                /*driver: MapUserModel(
                id: '3',
                name: 'DOGBE Joel',
                phone: '+22898797353',
                location: LatLng(6.140067, 1.21999),
                //avatarUrl: 'http://192.168.1.91:8000/storage/documents/r00LZRwK3qEzL5s8K9fb1XZWce33ps8D6DHBAVyx.jpg'
              ),
              vehicle: MapVehicleModel(
                id: '1',
                color: 'Verte',
                brandName: 'Toyota',
                modelName: 'Corolla',
                vehicleTypeName: 'Voiture',
                registrationNumber: 'TG-8909',
                //imageUrl: 'http://192.168.1.91:8000/storage/documents/r00LZRwK3qEzL5s8K9fb1XZWce33ps8D6DHBAVyx.jpg'
              ),*/
                package: MapDeliveryPackageModel(
                    id: '1',
                    type: 'Nourriture',
                    quantity: 1,
                    weightKg: 3.4,
                    volumeM3: 0.15,
                ),
                notes: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam mauris velit, viverra ac vestibulum vehicula, molestie sit amet nulla. Sed dui eros, '
                    'semper sit amet dui eget, fringilla vehicula tortor. Aliquam non imperdiet ante, a commodo eros. '
                    'Mauris venenatis, eros vitae vestibulum rhoncus, ante eros rutrum mi, '
                    'vitae congue nunc mauris ac arcu. Vivamus dapibus, odio imperdiet auctor tincidunt, nunc nunc semper dui, a tempor neque dui a sem. In ultricies odio a nisl fermentum luctus. Phasellus tempor risus ac nisl ornare sollicitudin. '
                    'Duis sit amet imperdiet arcu. Maecenas lorem leo, hendrerit quis mollis at, sagittis sit amet sapien. Curabitur facilisis ut purus quis cursus. Pellentesque sagittis velit sed est congue sagittis. Donec tempor efficitur tellus at ultrices. Mauris ut aliquet quam. '
                    'Cras accumsan sed nisi eget pharetra.',
                user: MapUserModel(
                  id: '2',
                  name: 'SEGBE Koffi',
                  phone: '+22898797353',
                  avatarUrl: null,
                )
            ),
            onCancelRequest: _cancelRequest,
            onCall: _callNumber,
            onFetchVehiclesErrorWidget: Center(
              child: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 24.0),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Icon(Icons.error, size: 80, color: Colors.black),
                    const SizedBox(height: 20),
                    Text(
                      'Aucun trajet disponible',
                      style: Theme.of(context).textTheme.headlineSmall?.copyWith(
                        color: Colors.black87,
                        fontWeight: FontWeight.bold,
                      ),
                      textAlign: TextAlign.center,
                    ),
                  ],
                ),
              ),
            ),
            buttonDeliveryPackageWidget: ListTile(

              leading: Icon(CupertinoIcons.archivebox_fill),
              title: Text('Selectionnez le package'),
              trailing: Icon(Icons.keyboard_arrow_right_outlined),
              onTap: (){
                flutterMapPackage.setMapDeliveryPackage(
                    MapDeliveryPackageModel(
                        id: '1'
                    )
                );
              },
            ),
          ),
        ],
      ),
    );
  }

/*Future<void> _showBottomSheet(BuildContext context){
    final size = MediaQuery.of(context).size;
    return showModalBottomSheet<void>(
      context: context,
      builder: (BuildContext context) {
        return SizedBox(
          height: size.height * 0.5,
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[

              ],
            ),
          ),
        );
      },
    );
  }*/
}
1
likes
130
points
11
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter package for interactive maps with trip planning, routing, dynamic markers and filtering. Supports Google Maps & OpenStreetMap (OSM) via OpenRouteService.

Repository (GitHub)
View/report issues
Contributing

Topics

#map #google-maps #openstreetmap #routing #location

Funding

Consider supporting this project:

buymeacoffee.com

License

MIT (license)

Dependencies

flutter, flutter_riverpod, flutter_spinkit, geocoding, geolocator, google_maps_flutter, google_maps_flutter_platform_interface, http, shared_preferences, uuid

More

Packages that depend on map_flutter