/
main.dart
210 lines (196 loc) · 7.23 KB
/
main.dart
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import 'package:example/widgets/liff_info.dart';
import 'package:flutter/material.dart';
import 'package:fimber/fimber.dart';
import 'package:flutter_line_liff/flutter_line_liff.dart';
import 'widgets/send_message_buttons.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
Fimber.plantTree(DebugTree());
FlutterLineLiff().init(
config: Config(liffId: 'xxxxxxxxxxxx'),
successCallback: () {
Fimber.d('LIFF init success.');
},
errorCallback: (error) {
Fimber.e(
'LIFF init error: ${error.name}, ${error.message}, ${error.stack}');
},
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _isInitDone = false;
String? _qrCodeV2Value;
String? _qrCodeV1Value;
@override
void initState() {
Fimber.d('message: ${const TemplateMessage(
altText: 'This is a buttons template',
template: TemplateButtons(text: 'Please select', actions: [
URIAction(label: 'Google', uri: 'https://www.google.com'),
]),
).toMap()}');
FlutterLineLiff().ready.then((_) {
setState(() {
_isInitDone = true;
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter LINE LIFF'),
),
body: !_isInitDone
? const Padding(
padding: EdgeInsets.all(16.0),
child: Center(child: Text('Wait for LIFF SDK initialize.')),
)
: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: CustomScrollView(
slivers: [
const SliverToBoxAdapter(
child: LiffInfo(),
),
SliverToBoxAdapter(
child: FutureBuilder<Profile>(
future: FlutterLineLiff().profile,
builder: (context, snapshot) => Text(
'Profile: ${snapshot.data?.toDebugString()}\n\n'),
),
),
SliverToBoxAdapter(
child: FutureBuilder<Friendship>(
future: FlutterLineLiff().friendship,
builder: (context, snapshot) => Text(
'Friendship: ${snapshot.data?.toDebugString()}\n\n'),
),
),
SliverToBoxAdapter(
child: TextButton(
onPressed: () {
if (!FlutterLineLiff().isLoggedIn) {
FlutterLineLiff().login();
} else {
FlutterLineLiff().logout();
}
},
child: Text(
FlutterLineLiff().isLoggedIn ? 'logout' : 'login'),
),
),
/// Permission section.
SliverToBoxAdapter(
child: TextButton(
onPressed: () {
FlutterLineLiff()
.permission
.query(Permission.chatMessageWrite)
.then((status) {
Fimber.d(
'Permission status: ${status.toDebugString()}');
}).onError((error, stackTrace) {
Fimber.e(
'Query Permission status with error: $error, $stackTrace');
});
},
child: const Text('Query Permission'),
),
),
SliverToBoxAdapter(
child: TextButton(
onPressed: () {
FlutterLineLiff().permission.requestAll().then((_) {
Fimber.d('Request All Permission done.');
}).onError((error, stackTrace) {
Fimber.e(
'Request All Permission with error: $error, $stackTrace');
});
},
child: const Text('Request All Permission'),
),
),
SliverToBoxAdapter(
child: TextButton(
onPressed: () {
FlutterLineLiff().closeWindow();
},
child: const Text('Close Window'),
),
),
/// Scan QRcode section.
SliverToBoxAdapter(
child: Column(
children: [
Text('QR Code V2 value: ${_qrCodeV2Value ?? ''}'),
TextButton(
onPressed: () {
setState(() {
_qrCodeV2Value = null;
});
FlutterLineLiff().scanCodeV2().then((result) {
setState(() {
_qrCodeV2Value = result.value;
});
}).onError((error, stackTrace) {
Fimber.e(
'Scan QR code V2 with error: $error, $stackTrace');
});
},
child: const Text('Scan QR code V2'),
),
],
),
),
/// Send Messages section.
const SliverToBoxAdapter(child: Text('Send Messages')),
const SliverToBoxAdapter(child: SendMessageButtons()),
/// ShareTarget section.
SliverToBoxAdapter(
child: TextButton(
onPressed: () {
FlutterLineLiff().shareTargetPicker(
messages: [
const TextMessage(
text: 'Share Target Test',
),
],
).onError((error, stackTrace) {
Fimber.e(
'Send messages with error: $error, $stackTrace');
return null;
}).then((result) {
Fimber.d(
'Share Target result: ${result?.toDebugString()}');
});
},
child: const Text('Share Target'),
),
),
],
),
),
);
}
}