secure_shared_preferences 0.0.1 secure_shared_preferences: ^0.0.1 copied to clipboard
A new Flutter project.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:secure_shared_preferences/secure_shared_preferences.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final TextEditingController _controller = TextEditingController();
String? data = "";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
controller: _controller,
),
Text(data ?? ""),
MaterialButton(
onPressed: _getData,
child: const Text("GetItBack"),
)
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _save,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
void _save() async {
var pref = await SecureSharedPref.getInstance();
pref.putString("StringEncrypted", "This is my first string test", true);
}
_getData() {
SecureSharedPref.getInstance().then((value) {
value.getString("StringEncrypted", true).then((value) {
setState(() {
data = value.toString();
});
});
});
}
}