| // Copyright 2016 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| import 'dart:async'; |
| |
| import 'package:flutter/material.dart'; |
| import 'package:flutter/services.dart'; |
| |
| class PlatformServices extends StatefulWidget { |
| @override |
| _PlatformServicesState createState() => new _PlatformServicesState(); |
| } |
| |
| class _PlatformServicesState extends State<PlatformServices> { |
| double _latitude; |
| double _longitude; |
| |
| @override |
| Widget build(BuildContext context) { |
| return new Material( |
| child: new Center( |
| child: new Column( |
| mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
| children: <Widget>[ |
| new Text('Hello from Flutter!'), |
| new RaisedButton( |
| child: new Text('Get Location'), |
| onPressed: _getLocation |
| ), |
| new Text('Latitude: $_latitude, Longitude: $_longitude'), |
| ] |
| ) |
| ) |
| ); |
| } |
| |
| Future<Null> _getLocation() async { |
| final Map<String, String> message = <String, String>{'provider': 'network'}; |
| final Map<String, dynamic> reply = await PlatformMessages.sendJSON('getLocation', message); |
| // If the widget was removed from the tree while the message was in flight, |
| // we want to discard the reply rather than calling setState to update our |
| // non-existent appearance. |
| if (!mounted) |
| return; |
| setState(() { |
| _latitude = reply['latitude'].toDouble(); |
| _longitude = reply['longitude'].toDouble(); |
| }); |
| } |
| } |
| |
| void main() { |
| runApp(new PlatformServices()); |
| } |