Created
July 27, 2018 15:05
-
-
Save debuging-life/1a6e715b98222085673f949f0019044d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:scoped_model/scoped_model.dart'; | |
| import '../../scoped-models/MainModel.dart'; | |
| import 'signup-steps/profile-information.dart'; | |
| import 'Login.dart'; | |
| import '../../models/User.dart'; | |
| class Register extends StatefulWidget { | |
| @override | |
| State<StatefulWidget> createState() { | |
| // TODO: implement createState | |
| return RegisterState(); | |
| } | |
| } | |
| class RegisterState extends State<Register> { | |
| final Map<String, dynamic> _formData = { | |
| 'firstName': null, | |
| 'email': null, | |
| 'password': null, | |
| }; | |
| final GlobalKey<FormState> _FirstStep = GlobalKey<FormState>(); | |
| TextEditingController _controller = new TextEditingController(); | |
| FocusNode _textFocus = new FocusNode(); | |
| @override | |
| void initState() { | |
| // TODO: implement initState | |
| _textFocus.addListener(onChange); | |
| super.initState(); | |
| } | |
| void onChange() { | |
| print(_controller.text); | |
| } | |
| // Email Field | |
| Widget _buildFirstNameField() { | |
| return Container( | |
| padding: EdgeInsets.symmetric(horizontal: 40.0), | |
| child: TextFormField( | |
| keyboardType: TextInputType.text, | |
| decoration: InputDecoration( | |
| labelText: "FIRST NAME", | |
| labelStyle: TextStyle( | |
| fontSize: 16.0, color: Color(0xFFff4f81), fontFamily: 'Lato'), | |
| ), | |
| validator: (String value) { | |
| if (value.isEmpty) { | |
| return 'First name is required'; | |
| } | |
| }, | |
| onSaved: (String value) { | |
| setState(() { | |
| _formData['firstName'] = value; | |
| }); | |
| }, | |
| ), | |
| ); | |
| } | |
| // Email Field | |
| Widget _buildEmailField() { | |
| return Container( | |
| padding: EdgeInsets.symmetric(horizontal: 40.0), | |
| child: TextFormField( | |
| keyboardType: TextInputType.emailAddress, | |
| decoration: InputDecoration( | |
| labelText: "EMAIL ID", | |
| labelStyle: TextStyle( | |
| fontSize: 16.0, color: Color(0xFFff4f81), fontFamily: 'Lato'), | |
| ), | |
| validator: (String value) { | |
| if (value.isEmpty || | |
| !RegExp(r"^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+") | |
| .hasMatch(value)) { | |
| return "Email is not valid"; | |
| } | |
| }, | |
| onSaved: (String value) { | |
| _formData['email'] = value; | |
| }, | |
| controller: _controller, | |
| focusNode: _textFocus, | |
| ), | |
| ); | |
| } | |
| // Password Field | |
| Widget _buildPasswordField() { | |
| return Container( | |
| padding: EdgeInsets.symmetric(horizontal: 40.0), | |
| child: TextFormField( | |
| keyboardType: TextInputType.text, | |
| decoration: InputDecoration( | |
| labelText: "PASSWORD", | |
| labelStyle: TextStyle( | |
| fontSize: 16.0, | |
| color: Color(0xFFff4f81), | |
| fontFamily: 'Lato', | |
| ), | |
| ), | |
| validator: (String value) { | |
| if (value.isEmpty) { | |
| return "Password is required"; | |
| } | |
| }, | |
| onSaved: (String value) { | |
| _formData['password'] = value; | |
| }, | |
| obscureText: true, | |
| ), | |
| ); | |
| } | |
| // Build Forgot password button | |
| Widget _buildForgotPassword() { | |
| return Container( | |
| alignment: Alignment.bottomRight, | |
| padding: EdgeInsets.only(right: 40.0), | |
| child: FlatButton( | |
| child: Text('Forgot Passowrd?', | |
| style: TextStyle( | |
| fontSize: 14.0, | |
| color: Color(0xFF717171), | |
| fontFamily: 'Lato', | |
| )), | |
| onPressed: () {}, | |
| ), | |
| ); | |
| } | |
| // SignIn Button | |
| Widget _buildSignUpButton() { | |
| return Center( | |
| child: Container( | |
| decoration: BoxDecoration( | |
| gradient: LinearGradient( | |
| begin: Alignment.bottomLeft, | |
| end: Alignment.centerRight, | |
| colors: [const Color(0xFFff976c), const Color(0xFFff4f81)], | |
| tileMode: TileMode.repeated, | |
| ), | |
| borderRadius: BorderRadius.circular(30.0), | |
| border: Border.all(color: Colors.transparent), | |
| ), | |
| padding: EdgeInsets.all(15.0), | |
| child: Text( | |
| 'NEXT STEP', | |
| style: TextStyle( | |
| color: Colors.white, | |
| fontFamily: 'Lato', | |
| ), | |
| ), | |
| width: 295.0, | |
| alignment: Alignment.center, | |
| ), | |
| ); | |
| } | |
| // Build Divider | |
| Widget _buildDivider() { | |
| return Row( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: <Widget>[ | |
| Container( | |
| width: 60.0, | |
| height: 3.0, | |
| decoration: BoxDecoration(color: Color(0xFFd6d6d6)), | |
| ), | |
| Padding( | |
| padding: const EdgeInsets.only(left: 10.0, right: 10.0), | |
| child: Text( | |
| 'OR', | |
| style: TextStyle( | |
| color: Color(0xFF717171), | |
| fontSize: 14.0, | |
| fontFamily: 'Lato', | |
| ), | |
| ), | |
| ), | |
| Container( | |
| width: 60.0, | |
| height: 3.0, | |
| decoration: BoxDecoration(color: Color(0xFFd6d6d6)), | |
| ), | |
| ], | |
| ); | |
| } | |
| // Build Signup Button | |
| Widget _buildSignInButton() { | |
| return Container( | |
| decoration: BoxDecoration( | |
| borderRadius: BorderRadius.circular(30.0), | |
| border: Border.all(color: Colors.pink, width: 1.0), | |
| ), | |
| padding: EdgeInsets.all(15.0), | |
| child: Text( | |
| 'SIGN IN', | |
| style: TextStyle( | |
| color: Colors.pink, | |
| fontFamily: 'Lato', | |
| ), | |
| ), | |
| width: 295.0, | |
| alignment: Alignment.center, | |
| ); | |
| } | |
| // Build SignIn Logo | |
| Widget _buildSignInLogo() { | |
| return Padding( | |
| padding: const EdgeInsets.only(top: 56.0, left: 39.0), | |
| child: Text( | |
| 'Register', | |
| style: TextStyle( | |
| fontSize: 40.0, | |
| color: Color(0xFFff4f81), | |
| fontFamily: 'Lato', | |
| ), | |
| ), | |
| ); | |
| } | |
| // Build Underline | |
| Widget _buildUnderLine() { | |
| return Padding( | |
| padding: const EdgeInsets.only( | |
| left: 39.0, | |
| top: 13.0, | |
| ), | |
| child: Container( | |
| height: 3.0, | |
| width: 116.0, | |
| decoration: BoxDecoration(color: Color(0xFFff4f81)), | |
| ), | |
| ); | |
| } | |
| SizedBox _buildSizeBox(double value) { | |
| return SizedBox( | |
| height: value, | |
| ); | |
| } | |
| void _submitForm(Function firstStep) { | |
| if (!_FirstStep.currentState.validate()) { | |
| return; | |
| } | |
| _FirstStep.currentState.save(); | |
| User user = User(firstName: _formData['firstName'], email: _formData['email'], password: _formData['password']); | |
| firstStep(user); | |
| Navigator.of(context).push( | |
| MaterialPageRoute( | |
| builder: (BuildContext context) => ProfileInformation( | |
| firstName: _formData['firstName'], | |
| email: _formData['email'], | |
| password: _formData['password'], | |
| ), | |
| ), | |
| ); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| // TODO: implement build | |
| return Scaffold( | |
| body: SingleChildScrollView( | |
| child: Form( | |
| key: _FirstStep, | |
| child: Column( | |
| crossAxisAlignment: CrossAxisAlignment.start, | |
| children: <Widget>[ | |
| _buildSignInLogo(), | |
| _buildUnderLine(), | |
| _buildSizeBox(30.0), | |
| _buildFirstNameField(), | |
| _buildSizeBox(20.0), | |
| _buildEmailField(), | |
| _buildSizeBox(20.0), | |
| _buildPasswordField(), | |
| _buildSizeBox(40.0), | |
| ScopedModelDescendant<RootModel>( | |
| builder: (context, child, RootModel model) { | |
| return InkWell( | |
| onTap: () { | |
| _submitForm(model.stepFirst); | |
| }, | |
| child: _buildSignUpButton(), | |
| ); | |
| }, | |
| ), | |
| _buildSizeBox(40.0), | |
| _buildDivider(), | |
| _buildSizeBox(40.0), | |
| Center( | |
| child: Container( | |
| child: InkWell( | |
| onTap: () { | |
| Navigator.of(context).pop(MaterialPageRoute(builder: ( | |
| BuildContext context | |
| ) => Login(),),); | |
| }, | |
| child: _buildSignInButton(), | |
| ), | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:flutter/services.dart'; | |
| // Pages | |
| import 'screens/auth/Login.dart'; | |
| import 'screens/auth/Register.dart'; | |
| import 'screens/auth/signup-steps/profile-information.dart'; | |
| import 'screens/auth/signup-steps/account-information.dart'; | |
| import 'screens/auth/forgot-password.dart'; | |
| import 'screens/main/home/home.dart'; | |
| import 'package:scoped_model/scoped_model.dart'; | |
| import 'scoped-models/MainModel.dart'; | |
| void main() { | |
| runApp(WeCracy()); | |
| } | |
| class WeCracy extends StatefulWidget { | |
| @override | |
| State<StatefulWidget> createState() { | |
| // TODO: implement createState | |
| return WeCracyState(); | |
| } | |
| } | |
| class WeCracyState extends State<WeCracy> { | |
| final RootModel _model = RootModel(); | |
| @override | |
| void initState() { | |
| _model.autologin(); | |
| super.initState(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith( | |
| statusBarIconBrightness: Brightness.dark | |
| )); | |
| // TODO: implement build | |
| return ScopedModel<RootModel>( | |
| model: _model, | |
| child: MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| title: "Wecracy App", | |
| theme: ThemeData( | |
| brightness: Brightness.light, | |
| primarySwatch: Colors.pink | |
| ), | |
| routes: { | |
| '/': (BuildContext context) => ScopedModelDescendant(builder: (BuildContext context, Widget child, RootModel model) { | |
| return model.user == null ? Login() : Home(); | |
| },), | |
| '/register': (BuildContext context) => Register(), | |
| '/profile': (BuildContext context) => ProfileInformation(), | |
| '/account': (BuildContext context) => AccountInformation(), | |
| '/forgot-password': (BuildContext context) => ForgotPassword(), | |
| '/home': (BuildContext context) => Home(), | |
| }, | |
| ), | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:scoped_model/scoped_model.dart'; | |
| import '../Register.dart'; | |
| import '../../../widgets/image.dart'; | |
| import '../../../scoped-models/UserModel.dart'; | |
| class ProfileInformation extends StatefulWidget { | |
| final String firstName; | |
| final String email; | |
| final String password; | |
| ProfileInformation({ this.firstName, this.email, this.password }); | |
| @override | |
| State<StatefulWidget> createState() { | |
| // TODO: implement createState | |
| return _ProfileInformationState(); | |
| } | |
| } | |
| class _ProfileInformationState extends State<ProfileInformation> { | |
| final UserModel _model = UserModel(); | |
| @override | |
| void initState() { | |
| // TODO: implement initState | |
| print(_model.getFirstStep); | |
| super.initState(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| // TODO: implement build | |
| return Scaffold( | |
| appBar: AppBar( | |
| elevation: 0.0, | |
| backgroundColor: Colors.transparent, | |
| leading: IconButton( | |
| icon: Icon(Icons.arrow_back_ios), | |
| onPressed: () => Navigator.of(context).pop( | |
| MaterialPageRoute( | |
| builder: (BuildContext context) => Register()), | |
| ), | |
| color: Color(0xFFff4f81), | |
| ), | |
| ), | |
| body: SingleChildScrollView( | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| crossAxisAlignment: CrossAxisAlignment.center, | |
| children: <Widget>[ | |
| _buildSizedBox(25.0), | |
| _buildLogoText(), | |
| _buildSizedBox(31.0), | |
| ImageInput(0xFF33b667, 'assets/avatar.png'), | |
| _buildSizedBox(46.0), | |
| _buildUsernameField(), | |
| _buildSizedBox(39.0), | |
| InkWell( | |
| child: _buildNextButton(), | |
| onTap: () => Navigator.of(context).pushNamed('/account'), | |
| ) | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| Widget _buildSizedBox(height) { | |
| return SizedBox( | |
| height: height, | |
| ); | |
| } | |
| Widget _buildLogoText() { | |
| return Padding( | |
| padding: const EdgeInsets.symmetric(horizontal: 45.0), | |
| child: Center( | |
| child: Text( | |
| 'Profile Information', | |
| style: TextStyle( | |
| color: Color(0xFFff4f81), fontSize: 28.0, fontFamily: 'Lato'), | |
| ), | |
| ), | |
| ); | |
| } | |
| // Email Field | |
| Widget _buildUsernameField() { | |
| return Container( | |
| padding: EdgeInsets.symmetric(horizontal: 40.0), | |
| child: TextFormField( | |
| keyboardType: TextInputType.emailAddress, | |
| decoration: InputDecoration( | |
| labelText: "USERNAME", | |
| labelStyle: TextStyle( | |
| fontSize: 16.0, color: Color(0xFFff4f81), fontFamily: 'Lato'), | |
| )), | |
| ); | |
| } | |
| // SignIn Button | |
| Widget _buildNextButton() { | |
| return Center( | |
| child: Container( | |
| decoration: BoxDecoration( | |
| gradient: LinearGradient( | |
| begin: Alignment.bottomLeft, | |
| end: Alignment.centerRight, | |
| colors: [const Color(0xFFff976c), const Color(0xFFff4f81)], | |
| tileMode: TileMode.repeated, | |
| ), | |
| borderRadius: BorderRadius.circular(30.0), | |
| border: Border.all(color: Colors.transparent), | |
| ), | |
| padding: EdgeInsets.all(15.0), | |
| child: Text( | |
| 'NEXT STEP', | |
| style: TextStyle( | |
| color: Colors.white, | |
| fontFamily: 'Lato', | |
| ), | |
| ), | |
| width: 295.0, | |
| alignment: Alignment.center, | |
| ), | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| class User { | |
| final String firstName; | |
| final String email; | |
| final String password; | |
| final String username; | |
| final String account; | |
| final bool token; | |
| User({ | |
| this.firstName, | |
| this.email, | |
| this.password, | |
| this.username, | |
| this.account, | |
| this.token | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:scoped_model/scoped_model.dart'; | |
| import 'package:shared_preferences/shared_preferences.dart'; | |
| import 'dart:async'; | |
| import 'package:http/http.dart' as http; | |
| import 'dart:convert'; | |
| import '../models/User.dart'; | |
| class UserModel extends Model { | |
| User _authenticatedUser; | |
| List<User> _registerData = []; | |
| bool _isLoading = false; | |
| final String apiUrl = "https://www.app-be-dev.wecracy.com"; | |
| stepFirst(User data) { | |
| print(data); | |
| _registerData.add(data); | |
| } | |
| List<User> get getFirstStep => _registerData; | |
| get user { | |
| return _authenticatedUser; | |
| } | |
| // Sign Up Api | |
| Future<Map<String, dynamic>> signup(String email, String password) async { | |
| final Map<String, dynamic> authData = { | |
| 'email': email, | |
| 'password': password | |
| }; | |
| final http.Response response = await http.post( | |
| '${apiUrl}/api/signup/v1/signup', | |
| body: jsonEncode(authData), | |
| ); | |
| return {'success': true, 'message': 'Account created successfully'}; | |
| } | |
| // Sign In Api | |
| Future<Map<String, dynamic>> signin(String email, String password) async { | |
| _isLoading = true; | |
| notifyListeners(); | |
| final Map<String, dynamic> authData = { | |
| 'identifier': email, | |
| 'password': password | |
| }; | |
| http.Response response = await http.post('${apiUrl}/api/auth/v1/login', | |
| body: jsonEncode(authData)); | |
| final Map<String, dynamic> responseData = json.decode(response.body); | |
| bool hasError = false; | |
| String token = ""; | |
| String message = 'You are logged in now'; | |
| if (responseData.containsKey('accessToken')) { | |
| hasError = true; | |
| _isLoading = false; | |
| notifyListeners(); | |
| token = responseData['accessToken']; | |
| notifyListeners(); | |
| } else { | |
| message = responseData['error']['message']; | |
| token = ""; | |
| hasError = false; | |
| _isLoading = false; | |
| notifyListeners(); | |
| } | |
| return {'success': hasError, 'message': message, 'token': token}; | |
| } | |
| bool get isLoading { | |
| return _isLoading; | |
| } | |
| void autologin() { | |
| bool autologin = null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment