Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import 'package:firebase_auth/firebase_auth.dart';
- // import 'dart:io';
- // import 'package:firebase_auth/firebase_auth.dart';
- import 'package:flutter/material.dart';
- import 'package:fluttertoast/fluttertoast.dart';
- import 'package:passwordsaver/services/auth.dart';
- import '../navigation_bloc/navigation_bloc.dart';
- class Setting extends StatefulWidget with NavigationStates {
- @override
- _SettingState createState() => _SettingState();
- }
- class _SettingState extends State<Setting> {
- final AuthService _auth = AuthService();
- //initialisation
- String _name = "";
- String _email = "";
- String _pass = "";
- String _passv = "";
- bool editname = true;
- bool editemail = true;
- bool editpass = true;
- bool show = false;
- // user defined function
- void _showDialog() {
- // flutter defined function
- showDialog(
- context: context,
- builder: (BuildContext context) {
- // return object of type Dialog
- return AlertDialog(
- title: new Text("Are You Sure?"),
- content: new Text(
- "Deleting this account will result in completely removing it from the system and you won't be able retrieve the saved data."),
- actions: <Widget>[
- // usually buttons at the bottom of the dialog
- FlatButton(
- child: new Text("DISMISS"),
- onPressed: () {
- Navigator.of(context).pop();
- },
- ),
- FlatButton(
- child: new Text("DELETE"),
- onPressed: () async {
- var user = await _auth.getCurrentuser();
- if (user != null) {
- user.delete().then((e) {
- Fluttertoast.showToast(
- msg: "Delete with Success",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.BOTTOM,
- timeInSecForIos: 1,
- );
- }).catchError((error) {
- Fluttertoast.showToast(
- msg: "Error while delete this account",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.BOTTOM,
- timeInSecForIos: 1,
- );
- });
- }
- Navigator.of(context).pop();
- },
- ),
- ],
- );
- },
- );
- }
- Widget deletebutton() {
- return InkWell(
- onTap: () {
- _showDialog();
- },
- child: Container(
- margin: EdgeInsets.only(
- left: (MediaQuery.of(context).size.width * 10) / 100,
- right: (MediaQuery.of(context).size.width * 10) / 100),
- height: 56.0,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(5.0),
- color: Color(0xFFF52525),
- ),
- child: Center(
- child: Text(
- "Delete Account",
- style: TextStyle(
- color: Colors.white,
- fontSize: 18.0,
- ),
- ),
- ),
- ),
- );
- }
- void getuser() async {
- var user = await _auth.getCurrentuser();
- if (user != null) {
- setState(() {
- _name = user.displayName;
- _email = user.email;
- });
- }
- }
- void verifem() async {
- print("hello");
- var user = await _auth.getCurrentuser();
- if (user.isEmailVerified) {
- setState(() {
- show = false;
- });
- } else if (user.isEmailVerified == false) {
- setState(() {
- show = true;
- });
- }
- }
- @override
- void initState() {
- getuser();
- verifem();
- super.initState();
- }
- void reload() async {
- var user = await _auth.getCurrentuser();
- await user.reload();
- }
- @override
- Widget build(BuildContext context) {
- reload();
- return Scaffold(
- appBar: AppBar(
- // backgroundColor: Colors.blue,
- leading: SizedBox(
- width: 10,
- ),
- title: Text(
- 'Settings',
- style: TextStyle(
- color: Colors.white,
- fontWeight: FontWeight.w900,
- ),
- ),
- ),
- body: SingleChildScrollView(
- child: Container(
- margin:
- EdgeInsets.all((MediaQuery.of(context).size.width * 15) / 100),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- TextFormField(
- onChanged: (val) {
- setState(() {
- _name = val;
- });
- },
- scrollPadding: EdgeInsets.all(50),
- readOnly: editname,
- initialValue: _name,
- // controller:TextEditingController(text:_name),
- decoration: InputDecoration(
- hintText: _name,
- border: OutlineInputBorder(
- borderRadius: BorderRadius.all(Radius.circular(5.0)),
- ),
- prefixIcon: Icon(Icons.person),
- suffixIcon: IconButton(
- icon: Icon(Icons.edit),
- onPressed: () async {
- verifem();
- if (show == false) {
- setState(() {
- editname = false;
- });
- } else {
- Fluttertoast.showToast(
- msg: "Verify Your Email",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.BOTTOM,
- timeInSecForIos: 1,
- );
- }
- },
- ),
- ),
- ),
- SizedBox(height: 10),
- TextFormField(
- onChanged: (val) {
- setState(() {
- _email = val;
- });
- },
- scrollPadding: EdgeInsets.all(50),
- readOnly: editemail,
- initialValue: _email,
- // controller:TextEditingController(text:_name),
- decoration: InputDecoration(
- hintText: _email,
- border: OutlineInputBorder(
- borderRadius: BorderRadius.all(Radius.circular(5.0)),
- ),
- prefixIcon: Icon(Icons.email),
- suffixIcon: IconButton(
- icon: Icon(Icons.edit),
- onPressed: () async {
- var v = await _auth.isEmailVerified();
- if (v) {
- setState(() {
- editemail = false;
- });
- } else {
- Fluttertoast.showToast(
- msg: "Verif Your Email",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.BOTTOM,
- timeInSecForIos: 1,
- );
- }
- },
- ),
- ),
- ),
- SizedBox(height: 10),
- TextFormField(
- onChanged: (val) {
- setState(() {
- _passv = val;
- });
- },
- scrollPadding: EdgeInsets.all(50),
- readOnly: editpass,
- initialValue: _pass,
- // controller:TextEditingController(text:_name),
- decoration: InputDecoration(
- hintText: "Old Password",
- border: OutlineInputBorder(
- borderRadius: BorderRadius.all(Radius.circular(5.0)),
- ),
- prefixIcon: Icon(Icons.security),
- ),
- ),
- SizedBox(height: 10),
- TextFormField(
- onChanged: (val) {
- setState(() {
- _pass = val;
- });
- },
- scrollPadding: EdgeInsets.all(50),
- readOnly: editpass,
- initialValue: _pass,
- // controller:TextEditingController(text:_name),
- decoration: InputDecoration(
- hintText: "New Password",
- border: OutlineInputBorder(
- borderRadius: BorderRadius.all(Radius.circular(5.0)),
- ),
- prefixIcon: Icon(Icons.security),
- suffixIcon: IconButton(
- icon: Icon(Icons.edit),
- onPressed: () async {
- var v = await _auth.isEmailVerified();
- if (v) {
- setState(() {
- editpass = false;
- });
- } else {
- Fluttertoast.showToast(
- msg: "Verif Your Email",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.BOTTOM,
- timeInSecForIos: 1,
- );
- }
- },
- ),
- ),
- ),
- SizedBox(height: 10),
- InkWell(
- onTap: () async {
- verifem();
- Fluttertoast.showToast(
- msg: "Reloaded",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.BOTTOM,
- timeInSecForIos: 1,
- );
- // var v=await _auth.isEmailVerified();
- // if(v){
- // dynamic result=await _auth.signInWithEmailAndPassword(_email, _passv);
- // if(result==null){
- // Fluttertoast.showToast(msg: "Wrong Password",toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIos: 1, );
- // }else{
- // await _auth.update(_name,_email,_pass);
- // Fluttertoast.showToast(msg: "Success",toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIos: 1, );
- // }
- // }
- // else
- // {
- // Fluttertoast.showToast(msg: "You must verify your email first.",toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIos: 1, );
- // }
- },
- child: Container(
- margin: EdgeInsets.only(
- left: (MediaQuery.of(context).size.width * 10) / 100,
- right: (MediaQuery.of(context).size.width * 10) / 100),
- height: 56.0,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(5.0),
- color: Theme.of(context).primaryColor,
- ),
- child: Center(
- child: Text(
- "Reload",
- style: TextStyle(
- color: Colors.white,
- fontSize: 18.0,
- ),
- ),
- ),
- ),
- ),
- Visibility(
- child: Column(
- children: <Widget>[
- SizedBox(height: 10),
- show
- ? InkWell(
- onTap: () async {
- var v = await _auth.isEmailVerified();
- if (!v) {
- String e = await _auth.sendEmailVerification();
- Fluttertoast.showToast(
- msg: e,
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.BOTTOM,
- timeInSecForIos: 1,
- );
- }
- },
- child: Container(
- margin: EdgeInsets.only(
- left:
- (MediaQuery.of(context).size.width * 10) /
- 100,
- right:
- (MediaQuery.of(context).size.width * 10) /
- 100),
- height: 56.0,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(5.0),
- color: Theme.of(context).primaryColor,
- ),
- child: Center(
- child: Text(
- "Send Email Verification",
- style: TextStyle(
- color: Colors.white,
- fontSize: 18.0,
- ),
- ),
- ),
- ),
- )
- : SizedBox.shrink(),
- ],
- ),
- visible: show,
- ),
- SizedBox(height: 10),
- deletebutton(),
- ],
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement