From 82bbdd99d08807d4f04b17dc237aece81c58d28e Mon Sep 17 00:00:00 2001 From: Moe Date: Mon, 25 Apr 2022 22:28:58 +0700 Subject: [PATCH] Cleanup Code --- lib/api/api.dart | 6 +++--- lib/components/menu.dart | 4 ++-- lib/components/register_error.dart | 8 ++++---- lib/components/register_form.dart | 20 ++++++++++---------- lib/components/register_verify.dart | 8 ++++---- lib/main.dart | 2 +- lib/screens/checkout.dart | 4 ++-- lib/screens/register.dart | 6 ++---- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/lib/api/api.dart b/lib/api/api.dart index 574cf09..26d05a0 100644 --- a/lib/api/api.dart +++ b/lib/api/api.dart @@ -13,14 +13,14 @@ Future getProduct(id) async { return res; } -Future RegisterPost({email, password, first_name, last_name}) async { +Future registerPost({email, password, firstName, lastName}) async { Response req = await Dio().post( (host + '/register'), data: { 'email': email, 'password': password, - 'first_name': first_name, - 'last_name': last_name + 'first_name': firstName, + 'last_name': lastName }, options: Options( contentType: Headers.formUrlEncodedContentType, diff --git a/lib/components/menu.dart b/lib/components/menu.dart index 6012f19..e8e5851 100644 --- a/lib/components/menu.dart +++ b/lib/components/menu.dart @@ -51,9 +51,9 @@ class _MenuState extends State { } else if (index == 2) { _selectedWidget = const Products(); } else if (index == 3) { - _selectedWidget = Checkout(); + _selectedWidget = const Checkout(); } else if (index == 4) { - _selectedWidget = Register(); + _selectedWidget = const Register(); } }); } diff --git a/lib/components/register_error.dart b/lib/components/register_error.dart index 4b5be3b..ecce460 100644 --- a/lib/components/register_error.dart +++ b/lib/components/register_error.dart @@ -1,14 +1,14 @@ import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart'; -class Register_Error extends StatefulWidget { - Register_Error({Key? key}) : super(key: key); +class RegisterError extends StatefulWidget { + const RegisterError({Key? key}) : super(key: key); @override - State createState() => _Register_ErrorState(); + State createState() => RegisterErrorState(); } -class _Register_ErrorState extends State { +class RegisterErrorState extends State { @override Widget build(BuildContext context) { return SafeArea( diff --git a/lib/components/register_form.dart b/lib/components/register_form.dart index c84d42c..29b162d 100644 --- a/lib/components/register_form.dart +++ b/lib/components/register_form.dart @@ -5,16 +5,16 @@ import 'package:nekoya_flutter/api/api.dart'; import 'package:nekoya_flutter/components/register_error.dart'; import 'package:nekoya_flutter/components/register_verify.dart'; -class Register_Form extends StatefulWidget { - Register_Form({Key? key}) : super(key: key); +class RegisterForm extends StatefulWidget { + const RegisterForm({Key? key}) : super(key: key); @override - State createState() => _Register_FormState(); + State createState() => RegisterFormState(); } final _formKey = GlobalKey(); -class _Register_FormState extends State { +class RegisterFormState extends State { @override Widget build(BuildContext context) { return SafeArea( @@ -84,10 +84,10 @@ class _Register_FormState extends State { '') { showAlertDialog(context); } else { - var statusCode = await RegisterPost( - first_name: _formKey.currentState! + var statusCode = await registerPost( + firstName: _formKey.currentState! .fields["First Name"]!.value, - last_name: _formKey.currentState! + lastName: _formKey.currentState! .fields["Last Name"]!.value, email: _formKey.currentState! .fields["Email Address"]!.value, @@ -99,13 +99,13 @@ class _Register_FormState extends State { context, MaterialPageRoute( builder: (context) => - Register_Verify())); + const RegisterVerify())); } else { Navigator.push( context, MaterialPageRoute( builder: (context) => - Register_Error())); + const RegisterError())); } } }, @@ -209,7 +209,7 @@ showAlertDialog(BuildContext context) { ), content: const Text( "Make sure to fill all text fields", - style: const TextStyle(color: Colors.white70), + style: TextStyle(color: Colors.white70), ), actions: [ okButton, diff --git a/lib/components/register_verify.dart b/lib/components/register_verify.dart index 14f17dd..6350f97 100644 --- a/lib/components/register_verify.dart +++ b/lib/components/register_verify.dart @@ -1,14 +1,14 @@ import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart'; -class Register_Verify extends StatefulWidget { - Register_Verify({Key? key}) : super(key: key); +class RegisterVerify extends StatefulWidget { + const RegisterVerify({Key? key}) : super(key: key); @override - State createState() => _Register_VerifyState(); + State createState() => RegisterVerifyState(); } -class _Register_VerifyState extends State { +class RegisterVerifyState extends State { @override Widget build(BuildContext context) { return SafeArea( diff --git a/lib/main.dart b/lib/main.dart index 6bf3a5b..ffbc45b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -20,7 +20,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( - colorScheme: ColorScheme.fromSwatch(accentColor: Color(0xff8B0000))), + colorScheme: ColorScheme.fromSwatch(accentColor: const Color(0xff8B0000))), home: AnimatedSplashScreen( splash: 'assets/logo_transparent.webp', pageTransitionType: PageTransitionType.fade, diff --git a/lib/screens/checkout.dart b/lib/screens/checkout.dart index e763f9a..c140f04 100644 --- a/lib/screens/checkout.dart +++ b/lib/screens/checkout.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class Checkout extends StatefulWidget { - Checkout({Key? key}) : super(key: key); + const Checkout({Key? key}) : super(key: key); @override State createState() => _CheckoutState(); @@ -17,7 +17,7 @@ class _CheckoutState extends State { centerTitle: true, backgroundColor: const Color(0xff212226), ), - body: Text('Checkout'), + body: const Text('Checkout'), ); } } diff --git a/lib/screens/register.dart b/lib/screens/register.dart index 47f84c0..28e42fc 100644 --- a/lib/screens/register.dart +++ b/lib/screens/register.dart @@ -1,10 +1,8 @@ import 'package:flutter/material.dart'; import 'package:nekoya_flutter/components/register_form.dart'; -import 'package:nekoya_flutter/components/register_verify.dart'; -import 'package:nekoya_flutter/components/register_error.dart'; class Register extends StatefulWidget { - Register({Key? key}) : super(key: key); + const Register({Key? key}) : super(key: key); @override State createState() => _RegisterState(); @@ -20,6 +18,6 @@ class _RegisterState extends State { centerTitle: true, backgroundColor: const Color(0xff212226), ), - body: Register_Form()); + body: const RegisterForm()); } }