Advertisement
Guest User

Profile

a guest
Feb 25th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 9.84 KB | None | 0 0
  1. import 'dart:io';
  2. import 'package:date_format/date_format.dart';
  3. import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:font_awesome_flutter/font_awesome_flutter.dart';
  6. import 'package:intl/intl.dart';
  7. import 'package:shared_preferences/shared_preferences.dart';
  8. import 'package:google_sign_in/google_sign_in.dart';
  9. import 'package:firebase_auth/firebase_auth.dart';
  10. import 'package:vivanews/main.dart';
  11. import 'package:vivanews/util/text_style_util.dart';
  12. import 'package:vivanews/view/screen/reset_screen.dart';
  13. import 'package:vivanews/view/screen/updateprofile_screen.dart';
  14. import 'package:intl/intl.dart';
  15.  
  16. class Profile extends StatefulWidget {
  17.   final VoidCallback signOut;
  18.  
  19.   Profile(this.signOut);
  20.  
  21.   @override
  22.   _ProfileState createState() => _ProfileState();
  23. }
  24.  
  25. class _ProfileState extends State<Profile> {
  26.   TextEditingController _controllername = new TextEditingController();
  27.   TextEditingController _controllerjk = new TextEditingController();
  28.   TextEditingController _controllertgl = new TextEditingController();
  29.   TextEditingController _controlleremail = new TextEditingController();
  30.   TextEditingController _controllerphone = new TextEditingController();
  31.   TextEditingController _controllerkota = new TextEditingController();
  32.   TextEditingController _controlleraddress = new TextEditingController();
  33.  
  34.   signOut() {
  35.     setState(() {
  36.       widget.signOut();
  37.     });
  38.   }
  39.  
  40.   File _image;
  41.  
  42.   String fullname = "";
  43.   String email = "";
  44.   String phonee = "";
  45.   String avatar = "";
  46.   String city = "";
  47.   String birth_date = "";
  48.   String addresss = "";
  49.   int status;
  50.   int gender;
  51.  
  52. //  int genderrr;
  53.  
  54.   getPref() async {
  55.     SharedPreferences preferences = await SharedPreferences.getInstance();
  56.     setState(() {
  57.       fullname = preferences.getString("fullname");
  58.       email = preferences.getString("email");
  59.       phonee = preferences.getString("phone");
  60.       avatar = preferences.getString("avatar");
  61.       city = preferences.getString("city");
  62.       birth_date = preferences.getString("birth_date");
  63.       addresss = preferences.getString("address");
  64.       status = preferences.getInt("status");
  65.       gender = preferences.getInt("gender");
  66.     });
  67.   }
  68.  
  69.   @override
  70.   void initState() {
  71.     // TODO: implement initState
  72.     super.initState();
  73.     getPref();
  74.  
  75.   }
  76.  
  77.   @override
  78.   Widget build(BuildContext context) {
  79.     _controllername.text = fullname;
  80.     if (gender == 1) {
  81.       _controllerjk.text = "Laki-Laki";
  82.     } else {
  83.       _controllerjk.text = "Perempuan";
  84.     }
  85.     _controlleremail.text = email;
  86.     _controllerphone.text = phonee;
  87.     _controllerkota.text = city;
  88.     _controlleraddress.text = addresss;
  89.     //DateTime tgl_lahir = DateTime.parse(birth_date);
  90.     String date = birth_date;
  91.     String dateWithT = date.substring(0, 10);
  92.     DateTime dateTime = DateTime.parse(dateWithT);
  93.     _controllertgl.text =
  94.     '${formatDate(dateTime, [dd, '-', mm, '-', yyyy])}';
  95.  
  96.  
  97.     final avatar_foto = Row(
  98.       mainAxisAlignment: MainAxisAlignment.center,
  99.       children: <Widget>[
  100.         Align(
  101.           alignment: Alignment.center,
  102.           child: CircleAvatar(
  103.             radius: 100,
  104.             backgroundColor: Colors.purple,
  105.             child: ClipOval(
  106.               child: new SizedBox(
  107.                 width: 180.0,
  108.                 height: 180.0,
  109.                 child: (_image != null)
  110.                     ? Image.file(
  111.                         _image,
  112.                         fit: BoxFit.fill,
  113.                       )
  114.                     : Image.network(
  115.                         avatar,
  116.                         fit: BoxFit.fill,
  117.                       ),
  118.               ),
  119.             ),
  120.           ),
  121.         ),
  122.       ],
  123.     );
  124.  
  125.  
  126.     final nama = TextFormField(
  127.       controller: _controllername,
  128.       autofocus: false,
  129.       enabled: false,
  130.       decoration: InputDecoration(
  131.         labelText: 'Nama Lengkap',
  132.         labelStyle: TextStyleUtil.textStyle(
  133.             fontSize: 18,
  134.           color: Colors.black,
  135.           fontWeight: FontWeight.bold
  136.       ),
  137.       ),
  138.     );
  139.  
  140.     final jk = TextFormField(
  141.       controller: _controllerjk,
  142.       enabled: false,
  143.       autofocus: false,
  144.       decoration: InputDecoration(
  145.         labelText: 'Jenis Kelamin',
  146.         labelStyle: TextStyleUtil.textStyle(
  147.             fontSize: 18,
  148.             color: Colors.black,
  149.             fontWeight: FontWeight.bold
  150.         ),
  151.       ),
  152.     );
  153.  
  154.     final tgl = TextFormField(
  155.       controller: _controllertgl,
  156.       enabled: false,
  157.       autofocus: false,
  158.       decoration: InputDecoration(
  159.         labelText: 'Tanggal Lahir',
  160.         labelStyle: TextStyleUtil.textStyle(
  161.             fontSize: 18,
  162.             color: Colors.black,
  163.             fontWeight: FontWeight.bold
  164.         ),
  165.       ),
  166.     );
  167.  
  168.  
  169.     final emailtext = TextFormField(
  170.       controller: _controlleremail,
  171.       enabled: false,
  172.       autofocus: false,
  173.       decoration: InputDecoration(
  174.         labelText: 'Email',
  175.         labelStyle: TextStyleUtil.textStyle(
  176.             fontSize: 18,
  177.             color: Colors.black,
  178.             fontWeight: FontWeight.bold
  179.         ),
  180.       ),
  181.     );
  182.  
  183.     final phone = TextFormField(
  184.       controller: _controllerphone,
  185.       autofocus: false,
  186.       enabled: false,
  187.       decoration: InputDecoration(
  188.         labelText: 'Nomor Telepon',
  189.         labelStyle: TextStyleUtil.textStyle(
  190.             fontSize: 18,
  191.             color: Colors.black,
  192.             fontWeight: FontWeight.bold
  193.         ),
  194.       ),
  195.     );
  196.  
  197.     final address = TextFormField(
  198.       controller: _controlleraddress,
  199.       autofocus: false,
  200.       enabled: false,
  201.       decoration: InputDecoration(
  202.         labelText: 'Alamat Lengkap',
  203.         labelStyle: TextStyleUtil.textStyle(
  204.             fontSize: 18,
  205.             color: Colors.black,
  206.             fontWeight: FontWeight.bold
  207.         ),
  208.       ),
  209.     );
  210.  
  211.     final kota = TextFormField(
  212.       controller: _controllerkota,
  213.       enabled: false,
  214.       autofocus: false,
  215.       decoration: InputDecoration(
  216.         labelText: 'Kota',
  217.         labelStyle: TextStyleUtil.textStyle(
  218.             fontSize: 18,
  219.             color: Colors.black,
  220.             fontWeight: FontWeight.bold
  221.         ),
  222.       ),
  223.     );
  224.  
  225.     final edit = RaisedButton(
  226.       onPressed: () {
  227.         Navigator.push(
  228.           context,
  229.           MaterialPageRoute(builder: (context) => UpdateProfile(signOut)),
  230.         );
  231.       },
  232.       color: Colors.purple,
  233.       child: Padding(
  234.         padding: const EdgeInsets.all(8.0),
  235.         child: Text(
  236.           'Edit',
  237.           style: TextStyle(fontSize: 18, color: Colors.white),
  238.         ),
  239.       ),
  240. //      elevation: 5,
  241.       shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
  242.     );
  243.  
  244.     final logout = RaisedButton(
  245.       onPressed: () {
  246.         MyApp().logoutGoogle();
  247.         MyApp().logoutfb();
  248.         signOut();
  249.       },
  250.       color: Colors.purple,
  251.       child: Padding(
  252.         padding: const EdgeInsets.all(8.0),
  253.         child: Text(
  254.           'Keluar',
  255.           style: TextStyle(fontSize: 18, color: Colors.white),
  256.         ),
  257.       ),
  258. //      elevation: 5,
  259.       shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
  260.     );
  261.  
  262.     final resetpass = RaisedButton(
  263.       onPressed: (){
  264.         Navigator.push(context, MaterialPageRoute(builder: (context) => ResetPass()),);
  265.       },
  266.       color: Colors.purple,
  267.       child: Padding(
  268.         padding: const EdgeInsets.all(8.0),
  269.         child: Text(
  270.           'Atur Kata Sandi',
  271.           style: TextStyle(fontSize: 18, color: Colors.white),
  272.         ),
  273.       ),
  274. //      elevation: 5,
  275.       shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
  276.     );
  277.  
  278.     return DefaultTabController(
  279.       length: 4,
  280.       child: Scaffold(
  281.         appBar: new AppBar(
  282.           title: new Text('Profil',
  283.               style: TextStyle(
  284.                   fontSize: 20.0,
  285.                   color: Colors.purple,
  286.                   fontWeight: FontWeight.bold)),
  287.           backgroundColor: Colors.white,
  288.           titleSpacing: -10,
  289.           leading: new IconButton(
  290.               icon: new Icon(Icons.home, color: Colors.purple)),
  291.           actions: <Widget>[
  292.             new IconButton(
  293.                 icon: new Icon(FontAwesomeIcons.gift, color: Colors.black)),
  294.             new IconButton(
  295.                 icon: new Icon(FontAwesomeIcons.history, color: Colors.black)),
  296.             new IconButton(
  297.                 icon: new Icon(FontAwesomeIcons.edit, color: Colors.black)),
  298.             new IconButton(
  299.                 onPressed: () {
  300.                   MyApp().logoutGoogle();
  301.                   MyApp().logoutfb();
  302.                   signOut();
  303.                 },
  304.                 icon:
  305.                     new Icon(FontAwesomeIcons.signOutAlt, color: Colors.black))
  306.           ],
  307.         ),
  308.         body: Form(
  309.           child: ListView(
  310.             shrinkWrap: true,
  311.             padding: EdgeInsets.only(left: 24.0, right: 24.0),
  312.             children: <Widget>[
  313.               SizedBox(height: 24.0),
  314.               avatar_foto,
  315.               SizedBox(height: 48.0),
  316.               nama,
  317.               SizedBox(height: 8.0),
  318.               jk,
  319.               SizedBox(height: 8.0),
  320.               tgl,
  321.               SizedBox(height: 8.0),
  322.               emailtext,
  323.               SizedBox(height: 8.0),
  324.               phone,
  325.               SizedBox(height: 8.0),
  326.               address,
  327.               SizedBox(height: 8.0),
  328.               kota,
  329.               SizedBox(height: 24.0),
  330.               edit,
  331.               SizedBox(height: 8.0),
  332.               resetpass,
  333.               SizedBox(height: 8.0),
  334.               logout,
  335.               SizedBox(height: 8.0)
  336.             ],
  337.           ),
  338.         ),
  339.       ),
  340.     );
  341.   }
  342. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement