123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- import 'package:flutter/material.dart';
- import 'package:flutter/widgets.dart';
- import 'package:logging/logging.dart';
- import 'package:photos/core/configuration.dart';
- import 'package:photos/core/event_bus.dart';
- import 'package:photos/events/subscription_purchased_event.dart';
- import 'package:photos/ui/common/dynamicFAB.dart';
- import 'package:photos/ui/recovery_page.dart';
- import 'package:photos/utils/dialog_util.dart';
- class PasswordReentryPage extends StatefulWidget {
- PasswordReentryPage({Key key}) : super(key: key);
- @override
- _PasswordReentryPageState createState() => _PasswordReentryPageState();
- }
- class _PasswordReentryPageState extends State<PasswordReentryPage> {
- final _passwordController = TextEditingController();
- final FocusNode _passwordFocusNode = FocusNode();
- bool _passwordInFocus = false;
- bool _passwordVisible = false;
- @override
- void initState() {
- super.initState();
- _passwordFocusNode.addListener(() {
- setState(() {
- _passwordInFocus = _passwordFocusNode.hasFocus;
- });
- });
- }
- @override
- Widget build(BuildContext context) {
- final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom != 0;
- FloatingActionButtonLocation fabLocation() {
- if (isKeypadOpen) {
- return null;
- } else {
- return FloatingActionButtonLocation.centerFloat;
- }
- }
- return Scaffold(
- appBar: AppBar(
- elevation: 0,
- leading: IconButton(
- icon: Icon(Icons.arrow_back),
- color: Theme.of(context).iconTheme.color,
- onPressed: () {
- Navigator.of(context).pop();
- },
- ),
- ),
- body: _getBody(),
- floatingActionButton: DynamicFAB(
- isKeypadOpen: isKeypadOpen,
- isFormValid: _passwordController.text.isNotEmpty,
- buttonText: 'Log in',
- onPressedFunction: () async {
- final dialog = createProgressDialog(context, "please wait...");
- await dialog.show();
- try {
- await Configuration.instance.decryptAndSaveSecrets(
- _passwordController.text,
- Configuration.instance.getKeyAttributes());
- } catch (e) {
- Logger("PRP").warning(e);
- await dialog.hide();
- showErrorDialog(
- context, "incorrect password", "please try again");
- return;
- }
- await dialog.hide();
- Bus.instance.fire(SubscriptionPurchasedEvent());
- Navigator.of(context).popUntil((route) => route.isFirst);
- },
- ),
- floatingActionButtonLocation: fabLocation());
- }
- Widget _getBody() {
- return Column(
- children: [
- Expanded(
- child: ListView(
- children: [
- Padding(
- padding:
- const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
- child: Text('Welcome back!',
- style: Theme.of(context).textTheme.headline4),
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(20, 24, 20, 0),
- child: TextFormField(
- autofillHints: [AutofillHints.password],
- decoration: InputDecoration(
- hintText: "enter your password",
- filled: true,
- contentPadding: EdgeInsets.all(20),
- border: UnderlineInputBorder(
- borderSide: BorderSide.none,
- borderRadius: BorderRadius.circular(6)),
- suffixIcon: _passwordInFocus
- ? IconButton(
- icon: Icon(
- _passwordVisible
- ? Icons.visibility
- : Icons.visibility_off,
- color: Theme.of(context).iconTheme.color,
- size: 20,
- ),
- onPressed: () {
- setState(() {
- _passwordVisible = !_passwordVisible;
- });
- },
- )
- : null,
- ),
- style: TextStyle(
- fontSize: 14,
- ),
- controller: _passwordController,
- autofocus: true,
- autocorrect: false,
- obscureText: !_passwordVisible,
- keyboardType: TextInputType.visiblePassword,
- focusNode: _passwordFocusNode,
- onChanged: (_) {
- setState(() {});
- },
- ),
- ),
- Padding(
- padding: const EdgeInsets.symmetric(vertical: 18),
- child: Divider(
- thickness: 1,
- ),
- ),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 20),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return RecoveryPage();
- },
- ),
- );
- },
- child: Container(
- child: Center(
- child: Text("forgot password",
- style: Theme.of(context)
- .textTheme
- .subtitle1
- .copyWith(
- fontSize: 14,
- decoration: TextDecoration.underline)),
- ),
- ),
- ),
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () async {
- final dialog =
- createProgressDialog(context, "please wait...");
- await dialog.show();
- await Configuration.instance.logout();
- await dialog.hide();
- Navigator.of(context)
- .popUntil((route) => route.isFirst);
- },
- child: Container(
- child: Center(
- child: Text("change email",
- style: Theme.of(context)
- .textTheme
- .subtitle1
- .copyWith(
- fontSize: 14,
- decoration: TextDecoration.underline)),
- ),
- ),
- ),
- ],
- ),
- )
- ],
- ),
- ),
- // Padding(padding: EdgeInsets.all(12)),
- // Container(
- // padding: const EdgeInsets.symmetric(horizontal: 60),
- // width: double.infinity,
- // height: 64,
- // child: OutlinedButton(
- // child: Text("log in"),
- // onPressed: _passwordController.text.isNotEmpty
- // ? () async {
- // final dialog =
- // createProgressDialog(context, "please wait...");
- // await dialog.show();
- // try {
- // await Configuration.instance.decryptAndSaveSecrets(
- // _passwordController.text,
- // Configuration.instance.getKeyAttributes());
- // } catch (e) {
- // Logger("PRP").warning(e);
- // await dialog.hide();
- // showErrorDialog(
- // context, "incorrect password", "please try again");
- // return;
- // }
- // await dialog.hide();
- // Bus.instance.fire(SubscriptionPurchasedEvent());
- // Navigator.of(context).popUntil((route) => route.isFirst);
- // }
- // : null,
- // ),
- // ),
- // Padding(padding: EdgeInsets.all(30)),
- ],
- );
- }
- }
|