Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
34c63aff
Commit
34c63aff
authored
Mar 01, 2017
by
Michael Thomsen
Committed by
GitHub
Mar 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update platform-services to new APIs (#8488)
parent
1b52d46b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
32 deletions
+12
-32
main.dart
examples/platform_services/lib/main.dart
+12
-32
No files found.
examples/platform_services/lib/main.dart
View file @
34c63aff
...
@@ -13,7 +13,16 @@ class PlatformServices extends StatefulWidget {
...
@@ -13,7 +13,16 @@ class PlatformServices extends StatefulWidget {
}
}
class
_PlatformServicesState
extends
State
<
PlatformServices
>
{
class
_PlatformServicesState
extends
State
<
PlatformServices
>
{
Future
<
dynamic
>
_locationRequest
;
static
const
PlatformMethodChannel
platform
=
const
PlatformMethodChannel
(
'geo'
);
String
_location
=
'Unknown location.'
;
Future
<
Null
>
_getLocation
()
async
{
List
<
double
>
result
=
await
platform
.
invokeMethod
(
'getLocation'
,
'network'
);
setState
(()
{
_location
=
'Latitude
${result[0]}
, Longitude
${result[1]}
.'
;
});
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -22,45 +31,16 @@ class _PlatformServicesState extends State<PlatformServices> {
...
@@ -22,45 +31,16 @@ class _PlatformServicesState extends State<PlatformServices> {
child:
new
Column
(
child:
new
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
<
Widget
>[
children:
<
Widget
>[
new
Text
(
'Hello from Flutter!'
),
new
RaisedButton
(
new
RaisedButton
(
child:
new
Text
(
'Get Location'
),
child:
new
Text
(
'Get Location'
),
onPressed:
_requestLocation
,
onPressed:
_getLocation
,
),
new
FutureBuilder
<
dynamic
>(
future:
_locationRequest
,
builder:
_buildLocation
,
),
),
new
Text
(
_location
)
],
],
),
),
),
),
);
);
}
}
void
_requestLocation
()
{
setState
(()
{
_locationRequest
=
const
PlatformMethodChannel
(
'geo'
).
invokeMethod
(
'getLocation'
,
'network'
,
);
});
}
Widget
_buildLocation
(
BuildContext
context
,
AsyncSnapshot
<
dynamic
>
snapshot
)
{
switch
(
snapshot
.
connectionState
)
{
case
ConnectionState
.
none
:
return
new
Text
(
'Press button to request location'
);
case
ConnectionState
.
waiting
:
return
new
Text
(
'Awaiting response...'
);
default
:
try
{
final
List
<
double
>
location
=
snapshot
.
requireData
;
return
new
Text
(
'Lat.
${location[0]}
, Long.
${location[1]}
'
);
}
on
PlatformException
catch
(
e
)
{
return
new
Text
(
'Request failed:
${e.message}
'
);
}
}
}
}
}
void
main
(
)
{
void
main
(
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment