|
|
|
@ -5,8 +5,8 @@ import 'package:flutter_example_packages/packages/flutter_secure_storage/package
|
|
|
|
|
import 'package:flutter_example_packages/widgets/base/export.dart'; |
|
|
|
|
import 'package:flutter_example_packages/widgets/blocks/block_alert.dart'; |
|
|
|
|
import 'package:flutter_example_packages/widgets/blocks/block_info_package.dart'; |
|
|
|
|
import 'package:flutter_example_packages/widgets/blocks/block_item.dart'; |
|
|
|
|
import 'package:flutter_example_packages/widgets/layouts/block_layout.dart'; |
|
|
|
|
import 'package:flutter_example_packages/widgets/texts/export.dart'; |
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; |
|
|
|
|
|
|
|
|
|
class FlutterSecureStoragePage extends AppStatefulWidget { |
|
|
|
@ -23,6 +23,31 @@ class FlutterSecureStoragePage extends AppStatefulWidget {
|
|
|
|
|
|
|
|
|
|
class _FlutterSecureStoragePageState |
|
|
|
|
extends AppState<FlutterSecureStoragePage> { |
|
|
|
|
bool _isValidSave = false; |
|
|
|
|
final TextEditingController _passSaveController = TextEditingController(); |
|
|
|
|
final TextEditingController _keySaveController = TextEditingController(); |
|
|
|
|
final TextEditingController _valueSaveController = TextEditingController(); |
|
|
|
|
|
|
|
|
|
bool _isValidGet = false; |
|
|
|
|
final TextEditingController _passGetController = TextEditingController(); |
|
|
|
|
final TextEditingController _keyGetController = TextEditingController(); |
|
|
|
|
final TextEditingController _valueGetController = TextEditingController(); |
|
|
|
|
|
|
|
|
|
void _validateSave() { |
|
|
|
|
setState(() { |
|
|
|
|
_isValidSave = _passSaveController.text.isNotEmpty && |
|
|
|
|
_keySaveController.text.isNotEmpty && |
|
|
|
|
_valueSaveController.text.isNotEmpty; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void _validateGet() { |
|
|
|
|
setState(() { |
|
|
|
|
_isValidGet = _passGetController.text.isNotEmpty && |
|
|
|
|
_keyGetController.text.isNotEmpty; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
Widget buildWide( |
|
|
|
|
BuildContext context, |
|
|
|
@ -32,6 +57,9 @@ class _FlutterSecureStoragePageState
|
|
|
|
|
return BlockLayout<FlutterSecureStorageModel>( |
|
|
|
|
title: widget.package.key, |
|
|
|
|
builder: (context, child, model) { |
|
|
|
|
// update read only value |
|
|
|
|
_valueGetController.text = model.readValue; |
|
|
|
|
// return widget |
|
|
|
|
return SingleChildScrollView( |
|
|
|
|
child: Padding( |
|
|
|
|
padding: const EdgeInsets.all(20), |
|
|
|
@ -44,10 +72,102 @@ class _FlutterSecureStoragePageState
|
|
|
|
|
Column( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
BlockItem( |
|
|
|
|
title: l10n.flutterSecureStorageTitle, |
|
|
|
|
desc: l10n.flutterSecureStorageDesc, |
|
|
|
|
value: null, |
|
|
|
|
TextTitleLarge(l10n.flutterSecureStorageTitleSave), |
|
|
|
|
const SizedBox(height: 14), |
|
|
|
|
if (model.isSuccess) |
|
|
|
|
BlockAlert( |
|
|
|
|
l10n.flutterSecureStorageSuccess, |
|
|
|
|
color: Colors.lightGreen, |
|
|
|
|
), |
|
|
|
|
const SizedBox(height: 6), |
|
|
|
|
TextField( |
|
|
|
|
controller: _passSaveController, |
|
|
|
|
decoration: InputDecoration( |
|
|
|
|
labelText: l10n.flutterSecureStorageFieldPass, |
|
|
|
|
), |
|
|
|
|
onChanged: (_) => _validateSave(), |
|
|
|
|
), |
|
|
|
|
const SizedBox(height: 16), |
|
|
|
|
TextField( |
|
|
|
|
controller: _keySaveController, |
|
|
|
|
decoration: InputDecoration( |
|
|
|
|
labelText: l10n.flutterSecureStorageFieldKey, |
|
|
|
|
), |
|
|
|
|
onChanged: (_) => _validateSave(), |
|
|
|
|
), |
|
|
|
|
const SizedBox(height: 16), |
|
|
|
|
TextField( |
|
|
|
|
controller: _valueSaveController, |
|
|
|
|
decoration: InputDecoration( |
|
|
|
|
labelText: l10n.flutterSecureStorageFieldValue, |
|
|
|
|
), |
|
|
|
|
onChanged: (_) => _validateSave(), |
|
|
|
|
), |
|
|
|
|
const SizedBox(height: 20), |
|
|
|
|
SizedBox( |
|
|
|
|
width: double.infinity, |
|
|
|
|
child: ElevatedButton( |
|
|
|
|
onPressed: _isValidSave |
|
|
|
|
? () => model.write( |
|
|
|
|
key: _keySaveController.text, |
|
|
|
|
value: _valueSaveController.text, |
|
|
|
|
password: _passSaveController.text, |
|
|
|
|
) |
|
|
|
|
: null, |
|
|
|
|
child: TextBodyLarge( |
|
|
|
|
l10n.flutterSecureStorageBtnSave, |
|
|
|
|
color: Colors.white, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
const SizedBox(height: 30), |
|
|
|
|
TextTitleLarge(l10n.flutterSecureStorageTitleGet), |
|
|
|
|
const SizedBox(height: 16), |
|
|
|
|
TextField( |
|
|
|
|
controller: _passGetController, |
|
|
|
|
decoration: InputDecoration( |
|
|
|
|
labelText: l10n.flutterSecureStorageFieldPass, |
|
|
|
|
), |
|
|
|
|
onChanged: (_) { |
|
|
|
|
_validateGet(); |
|
|
|
|
model.clearReadValue(); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
const SizedBox(height: 16), |
|
|
|
|
TextField( |
|
|
|
|
controller: _keyGetController, |
|
|
|
|
decoration: InputDecoration( |
|
|
|
|
labelText: l10n.flutterSecureStorageFieldKey, |
|
|
|
|
), |
|
|
|
|
onChanged: (_) { |
|
|
|
|
_validateGet(); |
|
|
|
|
model.clearReadValue(); |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
const SizedBox(height: 16), |
|
|
|
|
TextField( |
|
|
|
|
enabled: false, |
|
|
|
|
readOnly: true, |
|
|
|
|
controller: _valueGetController, |
|
|
|
|
decoration: InputDecoration( |
|
|
|
|
labelText: l10n.flutterSecureStorageFieldValue, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
const SizedBox(height: 20), |
|
|
|
|
SizedBox( |
|
|
|
|
width: double.infinity, |
|
|
|
|
child: ElevatedButton( |
|
|
|
|
onPressed: _isValidGet |
|
|
|
|
? () => model.read( |
|
|
|
|
key: _keyGetController.text, |
|
|
|
|
password: _passGetController.text, |
|
|
|
|
) |
|
|
|
|
: null, |
|
|
|
|
child: TextBodyLarge( |
|
|
|
|
l10n.flutterSecureStorageBtnGet, |
|
|
|
|
color: Colors.white, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|