Last active
January 14, 2020 18:26
-
-
Save AbhishekDoshi26/1d78ca5ca6d19ddd31b4a0a42ab86122 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:gps/gps.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:toast/toast.dart'; | |
import 'package:geolocator/geolocator.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: 'SOS Help', | |
theme: ThemeData( | |
primarySwatch: Colors.red, | |
), | |
home: MyHomePage(title: 'SOS Help'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
GpsLatlng latlng; | |
List<Placemark> placemark; | |
void initGps() async { | |
var gps = await Gps.currentGps(); | |
this.latlng = gps; | |
String temp = latlng.toString(); | |
String temp1="",temp2=""; | |
double lat,long; | |
int i=0; | |
while(temp[i]!=',') | |
{ | |
temp1+=temp[i]; | |
i++; | |
} | |
i+=2; | |
while(i!=temp.length) | |
{ | |
temp2+=temp[i]; | |
i++; | |
} | |
lat=double.parse(temp1); | |
long=double.parse(temp2); | |
print(lat); | |
print(long); | |
placemark = await Geolocator().placemarkFromCoordinates(lat,long); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("SOS"), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
MaterialButton( | |
color: Colors.red, | |
minWidth: 100.0, | |
height: 50.0, | |
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)), | |
splashColor: Colors.redAccent, | |
child: Text("SOS" | |
,style: TextStyle(color: Colors.white),), | |
onPressed: () | |
{ | |
initGps(); | |
Toast.show( | |
"$placemark", context, | |
duration: Toast.LENGTH_LONG, gravity: Toast.BOTTOM); //When displaying, here it shows [Instance of 'Placemark'] | |
} | |
) | |
], | |
), | |
), | |
// This trailing comma makes auto-formatting nicer for build methods. | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment