From 65e886653e274da7df78c3bd9164a0151ef74c87 Mon Sep 17 00:00:00 2001 From: Bijoy Ghosh Date: Fri, 5 Apr 2024 09:23:42 +0600 Subject: [PATCH] dart format updated --- example/lib/main.dart | 40 +++++++++++++++------------- lib/src/image_and_location_data.dart | 4 +-- lib/src/map_camera.dart | 40 +++++++++++++++++++--------- test/map_camera_flutter_test.dart | 4 +-- 4 files changed, 53 insertions(+), 35 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 4ad6d28..c3c2a68 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; import 'package:map_camera_flutter/map_camera_flutter.dart'; - -void main() async{ +void main() async { WidgetsFlutterBinding.ensureInitialized(); final cameras = await availableCameras(); final firstCamera = cameras.first; - runApp( MyApp(camera: firstCamera,)); + runApp(MyApp( + camera: firstCamera, + )); } class MyApp extends StatelessWidget { @@ -22,7 +23,10 @@ class MyApp extends StatelessWidget { colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), - home: MyHomePage(title: 'Camera With Map Location',camera: camera,), + home: MyHomePage( + title: 'Camera With Map Location', + camera: camera, + ), ); } } @@ -38,7 +42,6 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - @override void initState() { // TODO: implement initState @@ -48,18 +51,19 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - - title: Text(widget.title), - ), - body: MapCameraLocation(camera: widget.camera, onImageCaptured: (ImageAndLocationData data){ - print('Captured image path: ${data.imagePath}'); - print('Latitude: ${data.latitude}'); - print('Longitude: ${data.longitude}'); - print('Location name: ${data.locationName}'); - print('Sublocation: ${data.subLocation}'); - },) - ); + appBar: AppBar( + backgroundColor: Theme.of(context).colorScheme.inversePrimary, + title: Text(widget.title), + ), + body: MapCameraLocation( + camera: widget.camera, + onImageCaptured: (ImageAndLocationData data) { + print('Captured image path: ${data.imagePath}'); + print('Latitude: ${data.latitude}'); + print('Longitude: ${data.longitude}'); + print('Location name: ${data.locationName}'); + print('Sublocation: ${data.subLocation}'); + }, + )); } } diff --git a/lib/src/image_and_location_data.dart b/lib/src/image_and_location_data.dart index ee13845..bb4ad1d 100644 --- a/lib/src/image_and_location_data.dart +++ b/lib/src/image_and_location_data.dart @@ -1,4 +1,4 @@ -class ImageAndLocationData{ +class ImageAndLocationData { final String? imagePath; final String? latitude; final String? longitude; @@ -12,4 +12,4 @@ class ImageAndLocationData{ required this.locationName, required this.subLocation, }); -} \ No newline at end of file +} diff --git a/lib/src/map_camera.dart b/lib/src/map_camera.dart index 3a8565b..2ec2cc2 100644 --- a/lib/src/map_camera.dart +++ b/lib/src/map_camera.dart @@ -3,8 +3,6 @@ import 'dart:ui' as ui; import 'package:latlong2/latlong.dart' as lat; import '../../map_camera_flutter.dart'; - - ///import 'package:your_app/map_camera_flutter.dart'; // Import the file where the MapCameraLocation widget is defined /// ``` @@ -50,7 +48,6 @@ import '../../map_camera_flutter.dart'; /// } /// ``` - // Callback function type for capturing image and location data typedef ImageAndLocationCallback = void Function(ImageAndLocationData data); @@ -62,8 +59,9 @@ class MapCameraLocation extends StatefulWidget { /// /// The [camera] parameter is required and represents the camera to be used for capturing images. /// The [onImageCaptured] parameter is an optional callback function that will be triggered when an image and location data are captured. - const MapCameraLocation({Key? key, required this.camera, this.onImageCaptured}) : super(key: key); - + const MapCameraLocation( + {Key? key, required this.camera, this.onImageCaptured}) + : super(key: key); @override State createState() => _MapCameraLocationState(); @@ -71,42 +69,55 @@ class MapCameraLocation extends StatefulWidget { class _MapCameraLocationState extends State { late CameraController _controller; + /// Represents a controller for the camera, used to control camera-related operations. late Future _initializeControllerFuture; + /// Represents a future that resolves when the camera controller has finished initializing. late FollowOnLocationUpdate _followOnLocationUpdate; + /// Enum value indicating when to follow location updates. late StreamController _followCurrentLocationStreamController; + /// Stream controller used to track the current location. File? cameraImagePath; + /// File path of the captured camera image. File? ssImage; + /// File path of the captured screen shot image. String? dateTime; + /// A formatted string representing the current date and time. final globalKey = GlobalKey(); + /// Key used to uniquely identify and control a widget. Placemark? placeMark; + /// Represents geocoded location information. String? latitudeServer; + /// Latitude value of the current location as a string. String? longitudeServer; + /// Longitude value of the current location as a string. String? locationName; + /// Name of the current location as a string. String? subLocation; + /// Sublocation of the current location as a string. /// Callback function to retrieve the image and location data. @@ -137,7 +148,6 @@ class _MapCameraLocationState extends State { dateTime = DateFormat.yMd().add_jm().format(DateTime.now()); } - @override void dispose() { _controller.dispose(); @@ -342,7 +352,8 @@ class _MapCameraLocationState extends State { var rng = Random(); // Get the render boundary of the widget - final RenderRepaintBoundary boundary = globalKey.currentContext!.findRenderObject()! as RenderRepaintBoundary; + final RenderRepaintBoundary boundary = + globalKey.currentContext!.findRenderObject()! as RenderRepaintBoundary; // Capture the screen as an image ui.Image image = await boundary.toImage(); @@ -393,7 +404,8 @@ class _MapCameraLocationState extends State { final position = await _determinePosition(); // Retrieve the placemarks for the current position - final placemarks = await placemarkFromCoordinates(position.latitude, position.longitude); + final placemarks = + await placemarkFromCoordinates(position.latitude, position.longitude); if (placemarks.isNotEmpty) { final placemark = placemarks.first; @@ -402,12 +414,15 @@ class _MapCameraLocationState extends State { setState(() { latitudeServer = position.latitude.toString(); longitudeServer = position.longitude.toString(); - locationName = "${placemark.locality ?? ""}, ${placemark.administrativeArea ?? ""}, ${placemark.country ?? ""}"; - subLocation = "${placemark.street ?? ""}, ${placemark.thoroughfare ?? ""} ${placemark.administrativeArea ?? ""}"; + locationName = + "${placemark.locality ?? ""}, ${placemark.administrativeArea ?? ""}, ${placemark.country ?? ""}"; + subLocation = + "${placemark.street ?? ""}, ${placemark.thoroughfare ?? ""} ${placemark.administrativeArea ?? ""}"; }); if (kDebugMode) { - print("Latitude: $latitudeServer, Longitude: $longitudeServer, Location: $locationName"); + print( + "Latitude: $latitudeServer, Longitude: $longitudeServer, Location: $locationName"); } } else { // Handle case when no placemark is available @@ -456,7 +471,8 @@ class _MapCameraLocationState extends State { // Check if location permission is permanently denied if (permission == LocationPermission.deniedForever) { // Throw an exception if location permission is permanently denied - throw Exception('Location permissions are permanently denied, we cannot request permissions.'); + throw Exception( + 'Location permissions are permanently denied, we cannot request permissions.'); } // Get the current position diff --git a/test/map_camera_flutter_test.dart b/test/map_camera_flutter_test.dart index 98ac402..0da434d 100644 --- a/test/map_camera_flutter_test.dart +++ b/test/map_camera_flutter_test.dart @@ -1,7 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; void main() { - test('adds one to input values', () { - - }); + test('adds one to input values', () {}); }