From 6868d789c79fc73b5cb90011f52ea81aac76e69f Mon Sep 17 00:00:00 2001 From: jdeguzman Date: Thu, 16 May 2019 20:03:10 +0800 Subject: [PATCH] Add setup for secured storage view --- lib/screens/dashboard.dart | 3 + lib/widgets/secured_storage_view.dart | 102 ++++++++++++++++++++++++ lib/widgets/shared_preference_view.dart | 11 +-- pubspec.lock | 7 ++ pubspec.yaml | 1 + 5 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 lib/widgets/secured_storage_view.dart diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index d6ee029..a8a216c 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. import 'package:flutter/material.dart'; +import 'package:flutter_persistence_demo/widgets/secured_storage_view.dart'; import 'package:flutter_persistence_demo/widgets/shared_preference_view.dart'; class DashboardScreen extends StatefulWidget { @@ -25,6 +26,8 @@ class DashboardScreenState extends State { child: Column( children: [ SharedPreferenceView(), + Padding(padding: EdgeInsets.only(bottom: 30)), + SecuredStorageView(), ], ), ), diff --git a/lib/widgets/secured_storage_view.dart b/lib/widgets/secured_storage_view.dart new file mode 100644 index 0000000..0a8e496 --- /dev/null +++ b/lib/widgets/secured_storage_view.dart @@ -0,0 +1,102 @@ +// Copyright 2019 Joshua de Guzman (https://jmdg.io). 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:flutter/material.dart'; + +class SecuredStorageView extends StatefulWidget { + @override + State createState() { + return SecuredStorageViewState(); + } +} + +class SecuredStorageViewState extends State { + final String KEY_API_TOKEN = 'api_token'; + String _data = ""; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Secure storage of credential using\nflutter_secure_storage ^3.2.1+1', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: Colors.blue, + ), + ), + Padding(padding: EdgeInsets.only(bottom: 5)), + Text( + 'Stores data in Keychain (for iOS) and Keystore (for Android).', + style: TextStyle( + fontSize: 14, + ), + ), + Padding(padding: EdgeInsets.only(bottom: 10)), + ClipRRect( + borderRadius: BorderRadius.circular(10), + child: Container( + color: Colors.blue, + height: 150, + padding: EdgeInsets.all(10), + width: double.infinity, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + 'API TOKEN', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + Padding(padding: EdgeInsets.only(bottom: 5)), + Text( + '$_data', + style: TextStyle( + fontSize: 30, + color: Colors.white, + fontWeight: FontWeight.bold, + ), + ), + Padding(padding: EdgeInsets.only(bottom: 10)), + Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + RaisedButton( + child: Text('Generate'), + onPressed: _generatePassword, + ), + Padding(padding: EdgeInsets.all(10)), + RaisedButton( + child: Text('Save'), + onPressed: _savePassword, + ), + Padding(padding: EdgeInsets.all(10)), + RaisedButton( + child: Text('Read'), + onPressed: _readPassword, + ), + ], + ), + ], + ), + ), + ) + ], + ); + } + + _generatePassword() async {} + + _savePassword() async {} + + _readPassword() async {} +} diff --git a/lib/widgets/shared_preference_view.dart b/lib/widgets/shared_preference_view.dart index 721b0b9..087aa80 100644 --- a/lib/widgets/shared_preference_view.dart +++ b/lib/widgets/shared_preference_view.dart @@ -31,9 +31,9 @@ class SharedPreferenceViewState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - 'Storing simple data (shared_preferences 0.5.2)', + 'Storing simple data locally using\nshared_preferences ^0.5.2', style: TextStyle( - fontSize: 14, + fontSize: 16, fontWeight: FontWeight.bold, color: Colors.blue, ), @@ -50,7 +50,7 @@ class SharedPreferenceViewState extends State { borderRadius: BorderRadius.circular(10), child: Container( color: Colors.blue, - height: 175, + height: 150, padding: EdgeInsets.all(10), width: double.infinity, child: Column( @@ -58,10 +58,11 @@ class SharedPreferenceViewState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( - 'Counter (int)', + 'COUNTER', style: TextStyle( - fontSize: 20, + fontSize: 16, color: Colors.white, + fontWeight: FontWeight.bold, ), ), Padding(padding: EdgeInsets.only(bottom: 5)), diff --git a/pubspec.lock b/pubspec.lock index 5cc348c..dd15463 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -41,6 +41,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_secure_storage: + dependency: "direct main" + description: + name: flutter_secure_storage + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.1+1" flutter_test: dependency: "direct dev" description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index aad57ef..027a7ec 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,6 +24,7 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2 shared_preferences: ^0.5.2 + flutter_secure_storage: ^3.2.1+1 dev_dependencies: flutter_test: