dart format updated
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:map_camera_flutter/map_camera_flutter.dart';
|
import 'package:map_camera_flutter/map_camera_flutter.dart';
|
||||||
|
|
||||||
|
void main() async {
|
||||||
void main() async{
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
final cameras = await availableCameras();
|
final cameras = await availableCameras();
|
||||||
final firstCamera = cameras.first;
|
final firstCamera = cameras.first;
|
||||||
runApp( MyApp(camera: firstCamera,));
|
runApp(MyApp(
|
||||||
|
camera: firstCamera,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@@ -22,7 +23,10 @@ class MyApp extends StatelessWidget {
|
|||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||||
useMaterial3: true,
|
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> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
// TODO: implement initState
|
// TODO: implement initState
|
||||||
@@ -48,18 +51,19 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||||
|
title: Text(widget.title),
|
||||||
title: Text(widget.title),
|
),
|
||||||
),
|
body: MapCameraLocation(
|
||||||
body: MapCameraLocation(camera: widget.camera, onImageCaptured: (ImageAndLocationData data){
|
camera: widget.camera,
|
||||||
print('Captured image path: ${data.imagePath}');
|
onImageCaptured: (ImageAndLocationData data) {
|
||||||
print('Latitude: ${data.latitude}');
|
print('Captured image path: ${data.imagePath}');
|
||||||
print('Longitude: ${data.longitude}');
|
print('Latitude: ${data.latitude}');
|
||||||
print('Location name: ${data.locationName}');
|
print('Longitude: ${data.longitude}');
|
||||||
print('Sublocation: ${data.subLocation}');
|
print('Location name: ${data.locationName}');
|
||||||
},)
|
print('Sublocation: ${data.subLocation}');
|
||||||
);
|
},
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
class ImageAndLocationData{
|
class ImageAndLocationData {
|
||||||
final String? imagePath;
|
final String? imagePath;
|
||||||
final String? latitude;
|
final String? latitude;
|
||||||
final String? longitude;
|
final String? longitude;
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import 'dart:ui' as ui;
|
|||||||
import 'package:latlong2/latlong.dart' as lat;
|
import 'package:latlong2/latlong.dart' as lat;
|
||||||
import '../../map_camera_flutter.dart';
|
import '../../map_camera_flutter.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///import 'package:your_app/map_camera_flutter.dart'; // Import the file where the MapCameraLocation widget is defined
|
///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
|
// Callback function type for capturing image and location data
|
||||||
typedef ImageAndLocationCallback = void Function(ImageAndLocationData 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 [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.
|
/// 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
|
@override
|
||||||
State<MapCameraLocation> createState() => _MapCameraLocationState();
|
State<MapCameraLocation> createState() => _MapCameraLocationState();
|
||||||
@@ -71,42 +69,55 @@ class MapCameraLocation extends StatefulWidget {
|
|||||||
|
|
||||||
class _MapCameraLocationState extends State<MapCameraLocation> {
|
class _MapCameraLocationState extends State<MapCameraLocation> {
|
||||||
late CameraController _controller;
|
late CameraController _controller;
|
||||||
|
|
||||||
/// Represents a controller for the camera, used to control camera-related operations.
|
/// Represents a controller for the camera, used to control camera-related operations.
|
||||||
|
|
||||||
late Future<void> _initializeControllerFuture;
|
late Future<void> _initializeControllerFuture;
|
||||||
|
|
||||||
/// Represents a future that resolves when the camera controller has finished initializing.
|
/// Represents a future that resolves when the camera controller has finished initializing.
|
||||||
|
|
||||||
late FollowOnLocationUpdate _followOnLocationUpdate;
|
late FollowOnLocationUpdate _followOnLocationUpdate;
|
||||||
|
|
||||||
/// Enum value indicating when to follow location updates.
|
/// Enum value indicating when to follow location updates.
|
||||||
|
|
||||||
late StreamController<double?> _followCurrentLocationStreamController;
|
late StreamController<double?> _followCurrentLocationStreamController;
|
||||||
|
|
||||||
/// Stream controller used to track the current location.
|
/// Stream controller used to track the current location.
|
||||||
|
|
||||||
File? cameraImagePath;
|
File? cameraImagePath;
|
||||||
|
|
||||||
/// File path of the captured camera image.
|
/// File path of the captured camera image.
|
||||||
|
|
||||||
File? ssImage;
|
File? ssImage;
|
||||||
|
|
||||||
/// File path of the captured screen shot image.
|
/// File path of the captured screen shot image.
|
||||||
|
|
||||||
String? dateTime;
|
String? dateTime;
|
||||||
|
|
||||||
/// A formatted string representing the current date and time.
|
/// A formatted string representing the current date and time.
|
||||||
|
|
||||||
final globalKey = GlobalKey();
|
final globalKey = GlobalKey();
|
||||||
|
|
||||||
/// Key used to uniquely identify and control a widget.
|
/// Key used to uniquely identify and control a widget.
|
||||||
|
|
||||||
Placemark? placeMark;
|
Placemark? placeMark;
|
||||||
|
|
||||||
/// Represents geocoded location information.
|
/// Represents geocoded location information.
|
||||||
|
|
||||||
String? latitudeServer;
|
String? latitudeServer;
|
||||||
|
|
||||||
/// Latitude value of the current location as a string.
|
/// Latitude value of the current location as a string.
|
||||||
|
|
||||||
String? longitudeServer;
|
String? longitudeServer;
|
||||||
|
|
||||||
/// Longitude value of the current location as a string.
|
/// Longitude value of the current location as a string.
|
||||||
|
|
||||||
String? locationName;
|
String? locationName;
|
||||||
|
|
||||||
/// Name of the current location as a string.
|
/// Name of the current location as a string.
|
||||||
|
|
||||||
String? subLocation;
|
String? subLocation;
|
||||||
|
|
||||||
/// Sublocation of the current location as a string.
|
/// Sublocation of the current location as a string.
|
||||||
|
|
||||||
/// Callback function to retrieve the image and location data.
|
/// 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());
|
dateTime = DateFormat.yMd().add_jm().format(DateTime.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_controller.dispose();
|
_controller.dispose();
|
||||||
@@ -342,7 +352,8 @@ class _MapCameraLocationState extends State<MapCameraLocation> {
|
|||||||
var rng = Random();
|
var rng = Random();
|
||||||
|
|
||||||
// Get the render boundary of the widget
|
// 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
|
// Capture the screen as an image
|
||||||
ui.Image image = await boundary.toImage();
|
ui.Image image = await boundary.toImage();
|
||||||
@@ -393,7 +404,8 @@ class _MapCameraLocationState extends State<MapCameraLocation> {
|
|||||||
final position = await _determinePosition();
|
final position = await _determinePosition();
|
||||||
|
|
||||||
// Retrieve the placemarks for the current position
|
// 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) {
|
if (placemarks.isNotEmpty) {
|
||||||
final placemark = placemarks.first;
|
final placemark = placemarks.first;
|
||||||
@@ -402,12 +414,15 @@ class _MapCameraLocationState extends State<MapCameraLocation> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
latitudeServer = position.latitude.toString();
|
latitudeServer = position.latitude.toString();
|
||||||
longitudeServer = position.longitude.toString();
|
longitudeServer = position.longitude.toString();
|
||||||
locationName = "${placemark.locality ?? ""}, ${placemark.administrativeArea ?? ""}, ${placemark.country ?? ""}";
|
locationName =
|
||||||
subLocation = "${placemark.street ?? ""}, ${placemark.thoroughfare ?? ""} ${placemark.administrativeArea ?? ""}";
|
"${placemark.locality ?? ""}, ${placemark.administrativeArea ?? ""}, ${placemark.country ?? ""}";
|
||||||
|
subLocation =
|
||||||
|
"${placemark.street ?? ""}, ${placemark.thoroughfare ?? ""} ${placemark.administrativeArea ?? ""}";
|
||||||
});
|
});
|
||||||
|
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
print("Latitude: $latitudeServer, Longitude: $longitudeServer, Location: $locationName");
|
print(
|
||||||
|
"Latitude: $latitudeServer, Longitude: $longitudeServer, Location: $locationName");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Handle case when no placemark is available
|
// Handle case when no placemark is available
|
||||||
@@ -456,7 +471,8 @@ class _MapCameraLocationState extends State<MapCameraLocation> {
|
|||||||
// Check if location permission is permanently denied
|
// Check if location permission is permanently denied
|
||||||
if (permission == LocationPermission.deniedForever) {
|
if (permission == LocationPermission.deniedForever) {
|
||||||
// Throw an exception if location permission is permanently denied
|
// 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
|
// Get the current position
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('adds one to input values', () {
|
test('adds one to input values', () {});
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user