2020-08-26 01:43:10 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
2021-01-05 14:27:02 +00:00
|
|
|
import 'package:flutter_password_strength/flutter_password_strength.dart';
|
2020-10-03 17:56:18 +00:00
|
|
|
import 'package:photos/services/user_service.dart';
|
2020-10-24 21:07:12 +00:00
|
|
|
import 'package:photos/ui/common_elements.dart';
|
2020-08-26 01:43:10 +00:00
|
|
|
import 'package:photos/utils/dialog_util.dart';
|
|
|
|
|
2021-01-05 14:27:02 +00:00
|
|
|
class PasswordEntryPage extends StatefulWidget {
|
|
|
|
PasswordEntryPage({Key key}) : super(key: key);
|
2020-08-26 01:43:10 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-05 14:27:02 +00:00
|
|
|
_PasswordEntryPageState createState() => _PasswordEntryPageState();
|
2020-08-26 01:43:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 14:27:02 +00:00
|
|
|
class _PasswordEntryPageState extends State<PasswordEntryPage> {
|
|
|
|
final _passwordController1 = TextEditingController(),
|
|
|
|
_passwordController2 = TextEditingController();
|
2020-08-26 01:43:10 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2020-08-26 02:34:13 +00:00
|
|
|
leading: Icon(Icons.lock),
|
2021-01-05 14:17:45 +00:00
|
|
|
title: Text("encryption password"),
|
2020-08-26 01:43:10 +00:00
|
|
|
),
|
|
|
|
body: _getBody(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _getBody() {
|
2021-01-05 14:40:43 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
FlutterPasswordStrength(
|
|
|
|
password: _passwordController1.text,
|
|
|
|
backgroundColor: Colors.grey[850],
|
|
|
|
strengthCallback: (strength) {
|
|
|
|
debugPrint(strength.toString());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.fromLTRB(16, 36, 16, 16),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
// Image.asset(
|
|
|
|
// "assets/vault.png",
|
|
|
|
// width: 196,
|
|
|
|
// height: 196,
|
|
|
|
// ),
|
|
|
|
Padding(padding: EdgeInsets.all(12)),
|
|
|
|
Text(
|
|
|
|
"enter a password we can use to encrypt your data",
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
height: 1.3,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.all(8)),
|
|
|
|
Text("we don't store this password, so if you forget, "),
|
|
|
|
Text.rich(
|
|
|
|
TextSpan(
|
|
|
|
text: "we cannot decrypt your data",
|
|
|
|
style: TextStyle(
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
)),
|
|
|
|
style: TextStyle(
|
|
|
|
height: 1.3,
|
|
|
|
),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.all(12)),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
|
|
|
|
child: TextFormField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: "password",
|
|
|
|
contentPadding: EdgeInsets.all(20),
|
|
|
|
),
|
|
|
|
controller: _passwordController1,
|
|
|
|
autofocus: false,
|
|
|
|
autocorrect: false,
|
|
|
|
keyboardType: TextInputType.visiblePassword,
|
|
|
|
onChanged: (_) {
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.all(8)),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
|
|
|
|
child: TextFormField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: "password again",
|
|
|
|
contentPadding: EdgeInsets.all(20),
|
|
|
|
),
|
|
|
|
controller: _passwordController2,
|
|
|
|
autofocus: false,
|
|
|
|
autocorrect: false,
|
|
|
|
obscureText: true,
|
|
|
|
keyboardType: TextInputType.visiblePassword,
|
|
|
|
onChanged: (_) {
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2021-01-05 15:29:07 +00:00
|
|
|
Padding(padding: EdgeInsets.all(20)),
|
2021-01-05 14:40:43 +00:00
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
2021-01-05 15:29:07 +00:00
|
|
|
height: 64,
|
|
|
|
padding: EdgeInsets.fromLTRB(40, 0, 40, 0),
|
2021-01-05 14:40:43 +00:00
|
|
|
child: button(
|
|
|
|
"set password",
|
2021-01-05 15:29:07 +00:00
|
|
|
fontSize: 18,
|
2021-01-05 14:40:43 +00:00
|
|
|
onPressed: _passwordController1.text.isNotEmpty &&
|
|
|
|
_passwordController2.text.isNotEmpty
|
|
|
|
? () {
|
|
|
|
if (_passwordController1.text !=
|
|
|
|
_passwordController2.text) {
|
2021-01-08 17:06:52 +00:00
|
|
|
showErrorDialog(context, "uhm...",
|
|
|
|
"the passwords you entered don't match");
|
2021-01-05 14:40:43 +00:00
|
|
|
} else {
|
|
|
|
_showPasswordConfirmationDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
)),
|
|
|
|
],
|
2020-08-26 01:43:10 +00:00
|
|
|
),
|
|
|
|
),
|
2021-01-05 14:40:43 +00:00
|
|
|
),
|
2020-08-26 01:43:10 +00:00
|
|
|
),
|
2021-01-05 14:40:43 +00:00
|
|
|
],
|
2020-08-26 01:43:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-05 14:40:43 +00:00
|
|
|
void _showPasswordConfirmationDialog() {
|
2020-08-26 01:43:10 +00:00
|
|
|
AlertDialog alert = AlertDialog(
|
|
|
|
title: Text("Confirmation"),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: Column(children: [
|
2021-01-05 14:40:43 +00:00
|
|
|
Text("The password you are promising to never forget is"),
|
2020-08-26 01:43:10 +00:00
|
|
|
Padding(padding: EdgeInsets.all(8)),
|
2021-01-05 14:27:02 +00:00
|
|
|
Text(_passwordController1.text,
|
2020-08-26 01:43:10 +00:00
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 28,
|
|
|
|
)),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
FlatButton(
|
|
|
|
child: Text("Change"),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
FlatButton(
|
|
|
|
child: Text("Confirm"),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
2020-11-01 17:00:19 +00:00
|
|
|
UserService.instance
|
2021-01-05 14:27:02 +00:00
|
|
|
.setupAttributes(context, _passwordController1.text);
|
2020-08-26 01:43:10 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return alert;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|