Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:font_awesome_flutter/font_awesome_flutter.dart';
- import 'package:giffy_dialog/giffy_dialog.dart';
- import 'package:image_picker/image_picker.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:vivanews/share/constants.dart';
- import 'package:vivanews/view/component/loader.dart';
- import 'package:http/http.dart' as http;
- import 'package:email_validator/email_validator.dart';
- import 'package:vivanews/model/response.dart';
- import 'package:vivanews/model//usermodel.dart';
- import 'package:vivanews/view/screen/home_screen.dart';
- const List<Key> keys = [
- Key('Network'),
- Key('Network Dialog'),
- Key('Flare'),
- Key('Flare Dialog'),
- Key('Asset'),
- Key('Asset dialog'),
- ];
- String networking = 'https://media.giphy.com/media/26gJyevfC9ypAfLaM/giphy.gif';
- String networking2 = 'https://media.giphy.com/media/qwqqCWbiffgQM/giphy.gif';
- class Register extends StatefulWidget {
- final String valueEmail, valueNama;
- Register({Key key, this.valueEmail, this.valueNama}) : super(key: key);
- @override
- _RegisterState createState() => new _RegisterState();
- }
- class _RegisterState extends State<Register> {
- TextEditingController controllerUsername = new TextEditingController();
- TextEditingController controllerEmail = new TextEditingController();
- TextEditingController controllerFullname = new TextEditingController();
- TextEditingController controllerPhone = new TextEditingController();
- TextEditingController controllerPassword = new TextEditingController();
- TextEditingController confirmPassword = new TextEditingController();
- var _formKey = GlobalKey<FormState>();
- void addData() {
- var urlviva = Constants.REGISTER;
- http.post(urlviva, body: {
- "username": controllerUsername.text,
- "email": controllerEmail.text,
- "fullname": controllerFullname.text,
- "phone": controllerPhone.text,
- "password": controllerPassword.text
- }).then((response) {
- String responseBody = response.body;
- print("Response status: ${response.statusCode}");
- print("Response body: ${response.body}");
- Map userMap = jsonDecode(responseBody);
- var rs = Response.fromJson(userMap);
- print('${rs.message}!');
- print('${rs.status}');
- String message = rs.message;
- if (rs.status == 0) {
- showDialog(
- context: context,
- builder: (_) => FlareGiffyDialog(
- key: keys[3],
- flarePath: 'assets/teddy.flr',
- flareAnimation: 'fail',
- title: Text(
- "VIVA.CO.ID",
- style: TextStyle(
- fontSize: 22.0,
- fontWeight: FontWeight.bold,
- ),
- ),
- description: Text(
- message,
- textAlign: TextAlign.center,
- ),
- entryAnimation: EntryAnimation.TOP_LEFT,
- onOkButtonPressed: () {
- Navigator.pop(context);
- },
- ));
- new Future.delayed(const Duration(seconds: 5), () {
- Navigator.of(context, rootNavigator: true).pop();
- });
- return false;
- } else {
- showDialog(
- context: context,
- builder: (_) => FlareGiffyDialog(
- key: keys[3],
- flarePath: 'assets/teddy.flr',
- flareAnimation: 'success',
- title: Text(
- "VIVA.CO.ID",
- style: TextStyle(
- fontSize: 22.0,
- fontWeight: FontWeight.bold,
- ),
- ),
- description: Text(
- message,
- textAlign: TextAlign.center,
- ),
- entryAnimation: EntryAnimation.TOP_LEFT,
- onOkButtonPressed: () {
- Navigator.pop(context);
- },
- ));
- new Future.delayed(const Duration(seconds: 5), () {
- Navigator.of(context, rootNavigator: true).pop();
- });
- return true;
- }
- });
- }
- bool _isHidePassword = true;
- void _togglePasswordVisibility() {
- setState(() {
- _isHidePassword = !_isHidePassword;
- });
- }
- void _togglePasswordVisibility_c() {
- setState(() {
- _isHidePassword = !_isHidePassword;
- });
- }
- bool dialog = false;
- void _showDialog() {
- setState(() {
- dialog = true;
- });
- showDialog(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return Center(child: Loader());
- }).then((_) {
- addData();
- if (mounted) {
- setState(() {
- dialog = false; // dialog was closed
- });
- }
- });
- new Future.delayed(const Duration(seconds: 2), () {
- Navigator.of(context, rootNavigator: true).pop();
- });
- }
- @override
- Widget build(BuildContext context) {
- controllerFullname.text = "${widget.valueNama ?? ''}";
- controllerEmail.text = "${widget.valueEmail ?? ''}";
- final username = TextFormField(
- controller: controllerUsername,
- validator: (value) {
- if (value.isEmpty)
- return 'Username Harus di isi';
- else
- return null;
- },
- keyboardType: TextInputType.text,
- autofocus: false,
- enabled: true,
- decoration: InputDecoration(
- labelText: 'Username',
- ),
- );
- final emailtext = TextFormField(
- controller: controllerEmail,
- validator: (value) {
- if (value.isEmpty) return 'Email Harus di isi';
- if (!EmailValidator.validate(value, true))
- return 'Email Tidak Valid';
- else
- return null;
- },
- keyboardType: TextInputType.emailAddress,
- enabled: true,
- autofocus: false,
- decoration: InputDecoration(
- labelText: 'Email',
- ),
- );
- final fullname = TextFormField(
- controller: controllerFullname,
- validator: (value) {
- if (value.isEmpty)
- return 'Nama Lengkap Harus di isi';
- else
- return null;
- },
- keyboardType: TextInputType.text,
- autofocus: false,
- enabled: true,
- decoration: InputDecoration(
- labelText: 'Nama Lengkap',
- ),
- );
- final phone = TextFormField(
- controller: controllerPhone,
- validator: (value) {
- if (value.isEmpty) return 'No Handphone Harus di isi';
- if (value.length < 8) return "No Handphone Minimal 10 angka";
- if (value.length > 13)
- return "No Handphone Maksimal 13 Angka";
- else
- return null;
- },
- keyboardType: TextInputType.number,
- autofocus: false,
- enabled: true,
- decoration: InputDecoration(
- labelText: 'No Telephone',
- ),
- );
- final password = TextFormField(
- controller: controllerPassword,
- validator: (value) {
- if (value.isEmpty) return 'Password Harus di isi';
- if (value.length < 6)
- return "Password Minimal 6 Karakter";
- else
- return null;
- },
- obscureText: _isHidePassword,
- autofocus: false,
- keyboardType: TextInputType.text,
- decoration: InputDecoration(
- labelText: 'Password',
- suffixIcon: GestureDetector(
- onTap: () {
- _togglePasswordVisibility();
- },
- child: Icon(
- _isHidePassword ? Icons.visibility_off : Icons.visibility,
- color: _isHidePassword ? Colors.grey : Colors.purple,
- ),
- ),
- isDense: true,
- ),
- );
- final c_password = TextFormField(
- controller: confirmPassword,
- validator: (value) {
- if (value.isEmpty) return 'Konfirmasi Password Harus di isi';
- if (value != controllerPassword.text)
- return 'Konfirmasi Password Harus Sama';
- if (value.length < 6)
- return "Konfirmasi Password Minimal 6 Karakter";
- else
- return null;
- },
- obscureText: _isHidePassword,
- autofocus: false,
- keyboardType: TextInputType.text,
- decoration: InputDecoration(
- labelText: 'Konfirmasi Password',
- suffixIcon: GestureDetector(
- onTap: () {
- _togglePasswordVisibility_c();
- },
- child: Icon(
- _isHidePassword ? Icons.visibility_off : Icons.visibility,
- color: _isHidePassword ? Colors.grey : Colors.purple,
- ),
- ),
- isDense: true,
- ),
- );
- final register = RaisedButton(
- onPressed: () {
- if (_formKey.currentState.validate()) {
- _showDialog();
- }
- },
- color: Colors.purple,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(
- 'Register',
- style: TextStyle(fontSize: 25, color: Colors.white),
- ),
- ),
- elevation: 5,
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
- );
- return Scaffold(
- appBar: new AppBar(
- title: new Text('Register Member',
- style: TextStyle(
- fontSize: 20.0,
- color: Colors.black,
- fontWeight: FontWeight.bold)),
- backgroundColor: Colors.white,
- titleSpacing: -10,
- leading: new IconButton(
- icon: new Icon(FontAwesomeIcons.user, color: Colors.black)),
- ),
- body: Form(
- key: _formKey,
- child: ListView(
- shrinkWrap: true,
- padding: EdgeInsets.only(left: 24.0, right: 24.0),
- children: <Widget>[
- SizedBox(height: 24.0),
- username,
- SizedBox(height: 8.0),
- emailtext,
- SizedBox(height: 8.0),
- fullname,
- SizedBox(height: 8.0),
- phone,
- SizedBox(height: 8.0),
- password,
- SizedBox(height: 8.0),
- c_password,
- SizedBox(height: 24.0),
- register
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement