|
| 1 | +import 'package:final_app/Helper/BlockButton.dart'; |
| 2 | +import 'package:final_app/Helper/FoodCategories.dart'; |
| 3 | +import 'package:final_app/Helper/SubCategoriesApi.dart'; |
| 4 | +import 'package:final_app/Helper/TrendingNowApi.dart'; |
| 5 | +import 'package:final_app/api/loginApi.dart'; |
| 6 | +import 'package:final_app/models/user.dart'; |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | +import 'package:flutter_spinkit/flutter_spinkit.dart'; |
| 9 | +import 'package:google_fonts/google_fonts.dart'; |
| 10 | +import 'package:progress_dialog/progress_dialog.dart'; |
| 11 | + |
| 12 | +import '../Constants.dart'; |
| 13 | +import '../Preferences.dart'; |
| 14 | + |
| 15 | +class ProfilePage extends StatefulWidget { |
| 16 | + @override |
| 17 | + _ProfilePageState createState() => _ProfilePageState(); |
| 18 | +} |
| 19 | + |
| 20 | +class _ProfilePageState extends State<ProfilePage> { |
| 21 | + ProgressDialog pr; |
| 22 | + User user = new User(); |
| 23 | + |
| 24 | + @override |
| 25 | + initState() { |
| 26 | + super.initState(); |
| 27 | + initPrefs(); |
| 28 | + } |
| 29 | + |
| 30 | + void initPrefs() async { |
| 31 | + await Preferences.getUser().then((value) { |
| 32 | + setState(() { |
| 33 | + user = value; |
| 34 | + }); |
| 35 | + }); |
| 36 | + } |
| 37 | + |
| 38 | + @override |
| 39 | + Widget build(BuildContext context) { |
| 40 | + pr = ProgressDialog(context, |
| 41 | + isDismissible: false, |
| 42 | + customBody: Container( |
| 43 | + color: Colors.transparent, |
| 44 | + child: SpinKitCubeGrid( |
| 45 | + color: Theme.of(context).accentColor, |
| 46 | + ))); |
| 47 | + pr.style( |
| 48 | + backgroundColor: Colors.transparent, |
| 49 | + ); |
| 50 | + if (this.user.name != '--') { |
| 51 | + return Scaffold( |
| 52 | + backgroundColor: Colors.white70, |
| 53 | + body: Padding( |
| 54 | + padding: EdgeInsets.fromLTRB(30.4, 40.0, 30.0, 0.0), |
| 55 | + child: Column( |
| 56 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 57 | + children: <Widget>[ |
| 58 | + Center( |
| 59 | + child: CircleAvatar( |
| 60 | + backgroundImage: AssetImage('assets/profile.jpg'), |
| 61 | + radius: 40.0, |
| 62 | + ), |
| 63 | + ), |
| 64 | + Divider( |
| 65 | + height: 60.0, |
| 66 | + color: Colors.grey[700], |
| 67 | + ), |
| 68 | + Center( |
| 69 | + child: Text( |
| 70 | + "" + this.user.name, |
| 71 | + style: TextStyle( |
| 72 | + color: Colors.redAccent, |
| 73 | + fontSize: 28.0, |
| 74 | + fontWeight: FontWeight.bold, |
| 75 | + letterSpacing: 1.0, |
| 76 | + ), |
| 77 | + ), |
| 78 | + ), |
| 79 | + SizedBox( |
| 80 | + height: 30, |
| 81 | + ), |
| 82 | + Center( |
| 83 | + child: Text( |
| 84 | + "" + this.user.email, |
| 85 | + style: TextStyle( |
| 86 | + color: Colors.redAccent, |
| 87 | + fontSize: 20.0, |
| 88 | + fontWeight: FontWeight.bold, |
| 89 | + letterSpacing: 1.0, |
| 90 | + ), |
| 91 | + ), |
| 92 | + ), |
| 93 | + Center( |
| 94 | + child: FlatButton.icon( |
| 95 | + icon: Icon(Icons.edit), |
| 96 | + label: Text('Edit Profile', |
| 97 | + style: TextStyle(color: Colors.black87)), |
| 98 | + color: Colors.white70, |
| 99 | + onPressed: () {}, |
| 100 | + ), |
| 101 | + ), |
| 102 | + Center( |
| 103 | + child: RaisedButton.icon( |
| 104 | + icon: Icon( |
| 105 | + Icons.exit_to_app, |
| 106 | + color: Colors.white70, |
| 107 | + ), |
| 108 | + label: |
| 109 | + Text('Logout', style: TextStyle(color: Colors.white70)), |
| 110 | + color: Colors.redAccent, |
| 111 | + onPressed: () { |
| 112 | + CustomAlertDialog(context); |
| 113 | + }, |
| 114 | + ), |
| 115 | + ), |
| 116 | + ], |
| 117 | + ), |
| 118 | + ), |
| 119 | + ); |
| 120 | + } else { |
| 121 | + return Scaffold( |
| 122 | + backgroundColor: Colors.white70, |
| 123 | + body: Center( |
| 124 | + child: FlatButton( |
| 125 | + onPressed: () { |
| 126 | + Navigator.of(context).pushNamed('/LoginPage'); |
| 127 | + }, |
| 128 | + color: Colors.redAccent, |
| 129 | + child: Text( |
| 130 | + 'Login', |
| 131 | + style: TextStyle(color: Colors.black87, fontSize: 30), |
| 132 | + ), |
| 133 | + ), |
| 134 | + ), |
| 135 | + ); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + CustomAlertDialog(BuildContext context) { |
| 140 | + return showDialog( |
| 141 | + context: context, |
| 142 | + builder: (context) { |
| 143 | + return AlertDialog( |
| 144 | + title: Text( |
| 145 | + "Are you sure want to logout?", |
| 146 | + style: Theme.of(context).textTheme.subhead, |
| 147 | + ), |
| 148 | + actions: <Widget>[ |
| 149 | + MaterialButton( |
| 150 | + onPressed: () async { |
| 151 | +// Services _services = Services(); |
| 152 | + pr.show(); |
| 153 | + Login.LogoutUser().then((response) { |
| 154 | + pr.hide(); |
| 155 | + Navigator.pushNamed(context, '/LoginPage'); |
| 156 | + }); |
| 157 | + }, |
| 158 | + child: Text( |
| 159 | + "Yes", |
| 160 | + style: Theme.of(context).textTheme.subhead, |
| 161 | + ), |
| 162 | + ), |
| 163 | + MaterialButton( |
| 164 | + color: Theme.of(context).accentColor, |
| 165 | + onPressed: () { |
| 166 | + Navigator.of(context).pop(); |
| 167 | + }, |
| 168 | + child: Text( |
| 169 | + "No", |
| 170 | + style: Theme.of(context).textTheme.subhead, |
| 171 | + ), |
| 172 | + ) |
| 173 | + ], |
| 174 | + ); |
| 175 | + }); |
| 176 | + } |
| 177 | +} |
0 commit comments