dart format updated
This commit is contained in:
@@ -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<MyHomePage> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
@@ -50,16 +53,17 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: MapCameraLocation(camera: widget.camera, onImageCaptured: (ImageAndLocationData data){
|
||||
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}');
|
||||
},)
|
||||
);
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class ImageAndLocationData{
|
||||
class ImageAndLocationData {
|
||||
final String? imagePath;
|
||||
final String? latitude;
|
||||
final String? longitude;
|
||||
|
||||
@@ -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<MapCameraLocation> createState() => _MapCameraLocationState();
|
||||
@@ -71,42 +69,55 @@ class MapCameraLocation extends StatefulWidget {
|
||||
|
||||
class _MapCameraLocationState extends State<MapCameraLocation> {
|
||||
late CameraController _controller;
|
||||
|
||||
/// Represents a controller for the camera, used to control camera-related operations.
|
||||
|
||||
late Future<void> _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<double?> _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<MapCameraLocation> {
|
||||
dateTime = DateFormat.yMd().add_jm().format(DateTime.now());
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
@@ -342,7 +352,8 @@ class _MapCameraLocationState extends State<MapCameraLocation> {
|
||||
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<MapCameraLocation> {
|
||||
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<MapCameraLocation> {
|
||||
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<MapCameraLocation> {
|
||||
// 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
|
||||
|
||||
@@ -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', () {});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user