forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.dart
More file actions
169 lines (155 loc) · 5.2 KB
/
main.dart
File metadata and controls
169 lines (155 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright 2017 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 'package:android_intent/android_intent.dart';
import 'package:flutter/material.dart';
import 'package:platform/platform.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
routes: <String, WidgetBuilder>{
ExplicitIntentsWidget.routeName: (BuildContext context) =>
const ExplicitIntentsWidget()
},
);
}
}
class MyHomePage extends StatelessWidget {
void _createAlarm() {
final AndroidIntent intent = const AndroidIntent(
action: 'android.intent.action.SET_ALARM',
arguments: <String, dynamic>{
'android.intent.extra.alarm.DAYS': <int>[2, 3, 4, 5, 6],
'android.intent.extra.alarm.HOUR': 21,
'android.intent.extra.alarm.MINUTES': 30,
'android.intent.extra.alarm.SKIP_UI': true,
'android.intent.extra.alarm.MESSAGE': 'Create a Flutter app',
},
);
intent.launch();
}
void _openExplicitIntentsView(BuildContext context) {
Navigator.of(context).pushNamed(ExplicitIntentsWidget.routeName);
}
@override
Widget build(BuildContext context) {
Widget body;
if (const LocalPlatform().isAndroid) {
body = Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
child: const Text(
'Tap here to set an alarm\non weekdays at 9:30pm.'),
onPressed: _createAlarm,
),
RaisedButton(
child: const Text('Tap here to test explicit intents.'),
onPressed: () => _openExplicitIntentsView(context)),
],
),
);
} else {
body = const Text('This plugin only works with Android');
}
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(child: body),
);
}
}
class ExplicitIntentsWidget extends StatelessWidget {
const ExplicitIntentsWidget();
static const String routeName = "/explicitIntents";
void _openGoogleMapsStreetView() {
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('google.streetview:cbll=46.414382,10.013988'),
package: 'com.google.android.apps.maps');
intent.launch();
}
void _displayMapInGoogleMaps({int zoomLevel = 12}) {
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('geo:37.7749,-122.4194?z=$zoomLevel'),
package: 'com.google.android.apps.maps');
intent.launch();
}
void _launchTurnByTurnNavigationInGoogleMaps() {
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull(
'google.navigation:q=Taronga+Zoo,+Sydney+Australia&avoid=tf'),
package: 'com.google.android.apps.maps');
intent.launch();
}
void _openLinkInGoogleChrome() {
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('https://flutter.io'),
package: 'com.android.chrome');
intent.launch();
}
void _testExplicitIntentFallback() {
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('https://flutter.io'),
package: 'com.android.chrome.implicit.fallback');
intent.launch();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Test explicit intents'),
),
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
child: const Text(
'Tap here to display panorama\nimagery in Google Street View.'),
onPressed: _openGoogleMapsStreetView,
),
RaisedButton(
child: const Text('Tap here to display\na map in Google Maps.'),
onPressed: _displayMapInGoogleMaps,
),
RaisedButton(
child: const Text(
'Tap here to launch turn-by-turn\nnavigation in Google Maps.'),
onPressed: _launchTurnByTurnNavigationInGoogleMaps,
),
RaisedButton(
child: const Text('Tap here to open link in Google Chrome.'),
onPressed: _openLinkInGoogleChrome,
),
RaisedButton(
child: const Text(
'Tap here to test explicit intent fallback to implicit.'),
onPressed: _testExplicitIntentFallback,
),
],
),
),
),
);
}
}