Skip to content

Commit bbb0f6c

Browse files
julian-hartlJulianHartlsimeng-li
authored
feat(dart): add local storage persistence (#13)
Co-authored-by: julianhartl <julian.hartl@selectcode.de> Co-authored-by: simeng-li <simeng@silverhand.io>
1 parent 2ecd5eb commit bbb0f6c

14 files changed

+435
-102
lines changed

example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>9.0</string>
24+
<string>11.0</string>
2525
</dict>
2626
</plist>

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
# platform :ios, '9.0'
2+
# platform :ios, '11.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

example/lib/main.dart

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import 'package:http/http.dart' as http;
21
import 'package:flutter/material.dart';
2+
import 'package:http/http.dart' as http;
3+
import 'package:logto_dart_sdk/logto_dart_sdk.dart';
34

4-
import 'package:logto_dart_sdk/logto_client.dart';
5-
6-
void main() {
5+
void main() async {
6+
WidgetsFlutterBinding.ensureInitialized();
77
runApp(const MyApp());
88
}
99

@@ -38,6 +38,8 @@ class MyHomePage extends StatefulWidget {
3838

3939
class _MyHomePageState extends State<MyHomePage> {
4040
String content = 'Logto SDK Demo Home Page';
41+
bool isAuthenticated = false;
42+
4143
final client = http.Client();
4244
final redirectUri = 'io.logto://callback';
4345
final config = const LogtoConfig(
@@ -51,24 +53,39 @@ class _MyHomePageState extends State<MyHomePage> {
5153
_init();
5254
}
5355

56+
void render() async {
57+
if (await logtoClient.isAuthenticated) {
58+
var claims = await logtoClient.idTokenClaims;
59+
setState(() {
60+
content = claims!.toJson().toString();
61+
isAuthenticated = true;
62+
});
63+
}
64+
}
65+
5466
void _init() async {
5567
logtoClient = LogtoClient(config, client);
68+
render();
5669
}
5770

5871
void signInCallback() {
59-
if (logtoClient.isAuthenticate) {
60-
setState(() {
61-
var claims = logtoClient.idTokenClaims?.toJson();
62-
63-
if (claims != null) {
64-
content = claims.entries.map((e) => '${e.key}:${e.value}').join("\n");
65-
}
66-
});
67-
}
72+
render();
6873
}
6974

7075
@override
7176
Widget build(BuildContext context) {
77+
Widget signInButton = TextButton(
78+
style: TextButton.styleFrom(
79+
backgroundColor: Colors.deepPurpleAccent,
80+
padding: const EdgeInsets.all(16.0),
81+
textStyle: const TextStyle(fontSize: 20),
82+
),
83+
onPressed: () {
84+
logtoClient.signIn(context, redirectUri, signInCallback);
85+
},
86+
child: const Text('Sign In'),
87+
);
88+
7289
return Scaffold(
7390
appBar: AppBar(
7491
title: Text(widget.title),
@@ -79,21 +96,12 @@ class _MyHomePageState extends State<MyHomePage> {
7996
children: <Widget>[
8097
Container(
8198
padding: const EdgeInsets.all(64),
82-
child: Text(
99+
child: SelectableText(
83100
content,
84101
),
85102
),
86-
TextButton(
87-
style: TextButton.styleFrom(
88-
backgroundColor: Colors.deepPurpleAccent,
89-
padding: const EdgeInsets.all(16.0),
90-
textStyle: const TextStyle(fontSize: 20),
91-
),
92-
onPressed: () {
93-
logtoClient.signIn(context, redirectUri, signInCallback);
94-
},
95-
child: const Text('Sign In'),
96-
),
103+
// TODO: show signout button
104+
isAuthenticated ? signInButton : signInButton,
97105
],
98106
),
99107
),

example/pubspec.lock

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ packages:
3535
name: async
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "2.8.2"
38+
version: "2.9.0"
3939
boolean_selector:
4040
dependency: transitive
4141
description:
@@ -49,21 +49,14 @@ packages:
4949
name: characters
5050
url: "https://pub.dartlang.org"
5151
source: hosted
52-
version: "1.2.0"
53-
charcode:
54-
dependency: transitive
55-
description:
56-
name: charcode
57-
url: "https://pub.dartlang.org"
58-
source: hosted
59-
version: "1.3.1"
52+
version: "1.2.1"
6053
clock:
6154
dependency: transitive
6255
description:
6356
name: clock
6457
url: "https://pub.dartlang.org"
6558
source: hosted
66-
version: "1.1.0"
59+
version: "1.1.1"
6760
collection:
6861
dependency: transitive
6962
description:
@@ -112,7 +105,7 @@ packages:
112105
name: fake_async
113106
url: "https://pub.dartlang.org"
114107
source: hosted
115-
version: "1.3.0"
108+
version: "1.3.1"
116109
file:
117110
dependency: transitive
118111
description:
@@ -132,11 +125,58 @@ packages:
132125
url: "https://pub.dartlang.org"
133126
source: hosted
134127
version: "2.0.1"
128+
flutter_secure_storage:
129+
dependency: transitive
130+
description:
131+
name: flutter_secure_storage
132+
url: "https://pub.dartlang.org"
133+
source: hosted
134+
version: "6.0.0"
135+
flutter_secure_storage_linux:
136+
dependency: transitive
137+
description:
138+
name: flutter_secure_storage_linux
139+
url: "https://pub.dartlang.org"
140+
source: hosted
141+
version: "1.1.1"
142+
flutter_secure_storage_macos:
143+
dependency: transitive
144+
description:
145+
name: flutter_secure_storage_macos
146+
url: "https://pub.dartlang.org"
147+
source: hosted
148+
version: "1.1.1"
149+
flutter_secure_storage_platform_interface:
150+
dependency: transitive
151+
description:
152+
name: flutter_secure_storage_platform_interface
153+
url: "https://pub.dartlang.org"
154+
source: hosted
155+
version: "1.0.0"
156+
flutter_secure_storage_web:
157+
dependency: transitive
158+
description:
159+
name: flutter_secure_storage_web
160+
url: "https://pub.dartlang.org"
161+
source: hosted
162+
version: "1.0.2"
163+
flutter_secure_storage_windows:
164+
dependency: transitive
165+
description:
166+
name: flutter_secure_storage_windows
167+
url: "https://pub.dartlang.org"
168+
source: hosted
169+
version: "1.1.2"
135170
flutter_test:
136171
dependency: "direct dev"
137172
description: flutter
138173
source: sdk
139174
version: "0.0.0"
175+
flutter_web_plugins:
176+
dependency: transitive
177+
description: flutter
178+
source: sdk
179+
version: "0.0.0"
140180
frontend_server_client:
141181
dependency: transitive
142182
description:
@@ -227,21 +267,21 @@ packages:
227267
name: matcher
228268
url: "https://pub.dartlang.org"
229269
source: hosted
230-
version: "0.12.11"
270+
version: "0.12.12"
231271
material_color_utilities:
232272
dependency: transitive
233273
description:
234274
name: material_color_utilities
235275
url: "https://pub.dartlang.org"
236276
source: hosted
237-
version: "0.1.4"
277+
version: "0.1.5"
238278
meta:
239279
dependency: transitive
240280
description:
241281
name: meta
242282
url: "https://pub.dartlang.org"
243283
source: hosted
244-
version: "1.7.0"
284+
version: "1.8.0"
245285
mime:
246286
dependency: transitive
247287
description:
@@ -276,7 +316,7 @@ packages:
276316
name: path
277317
url: "https://pub.dartlang.org"
278318
source: hosted
279-
version: "1.8.1"
319+
version: "1.8.2"
280320
plugin_platform_interface:
281321
dependency: transitive
282322
description:
@@ -365,7 +405,7 @@ packages:
365405
name: source_span
366406
url: "https://pub.dartlang.org"
367407
source: hosted
368-
version: "1.8.2"
408+
version: "1.9.0"
369409
stack_trace:
370410
dependency: transitive
371411
description:
@@ -386,35 +426,35 @@ packages:
386426
name: string_scanner
387427
url: "https://pub.dartlang.org"
388428
source: hosted
389-
version: "1.1.0"
429+
version: "1.1.1"
390430
term_glyph:
391431
dependency: transitive
392432
description:
393433
name: term_glyph
394434
url: "https://pub.dartlang.org"
395435
source: hosted
396-
version: "1.2.0"
436+
version: "1.2.1"
397437
test:
398438
dependency: transitive
399439
description:
400440
name: test
401441
url: "https://pub.dartlang.org"
402442
source: hosted
403-
version: "1.21.1"
443+
version: "1.21.4"
404444
test_api:
405445
dependency: transitive
406446
description:
407447
name: test_api
408448
url: "https://pub.dartlang.org"
409449
source: hosted
410-
version: "0.4.9"
450+
version: "0.4.12"
411451
test_core:
412452
dependency: transitive
413453
description:
414454
name: test_core
415455
url: "https://pub.dartlang.org"
416456
source: hosted
417-
version: "0.4.13"
457+
version: "0.4.16"
418458
typed_data:
419459
dependency: transitive
420460
description:

0 commit comments

Comments
 (0)