Skip to content

Instantly share code, notes, and snippets.

@relwen
Created January 9, 2023 19:40
Show Gist options
  • Save relwen/ecdbca0adbd3ae6f2900246a8e0a1c68 to your computer and use it in GitHub Desktop.
Save relwen/ecdbca0adbd3ae6f2900246a8e0a1c68 to your computer and use it in GitHub Desktop.
import 'package:adan_sv/data/model/body/register_model.dart';
import 'package:adan_sv/helper/email_checker.dart';
import 'package:adan_sv/localization/language_constrants.dart';
import 'package:adan_sv/provider/auth_provider.dart';
import 'package:adan_sv/utill/color_resources.dart';
import 'package:adan_sv/utill/dimensions.dart';
import 'package:adan_sv/utill/styles.dart';
import 'package:adan_sv/view/base/custom_app_bar.dart';
import 'package:adan_sv/view/base/custom_button.dart';
import 'package:adan_sv/view/base/custom_snackbar.dart';
import 'package:adan_sv/view/screens/auth/widgets/info_field_view.dart';
import 'package:adan_sv/view/screens/auth/widgets/successfully_registered_screen.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class RegistrationScreen extends StatefulWidget {
const RegistrationScreen({Key key}) : super(key: key);
@override
State<RegistrationScreen> createState() => _RegistrationScreenState();
}
class _RegistrationScreenState extends State<RegistrationScreen>
with TickerProviderStateMixin {
TabController _tabController;
int selectedIndex = 0;
bool gpsEnabled = false;
@override
void initState() {
super.initState();
_tabController = TabController(length: 3, initialIndex: 0, vsync: this);
_tabController?.addListener(() {
switch (_tabController.index) {
case 0:
Provider.of<AuthProvider>(context, listen: false)
.setIndexForTabBar(0, isNotify: true);
break;
case 1:
Provider.of<AuthProvider>(context, listen: false)
.setIndexForTabBar(1, isNotify: true);
break;
case 2:
Provider.of<AuthProvider>(context, listen: false)
.setIndexForTabBar(2, isNotify: true);
break;
}
});
}
@override
void dispose() {
_tabController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(
title: getTranslated('shop_application', context),
isBackButtonExist: false),
body: Consumer<AuthProvider>(builder: (authContext, authProvider, _) {
return Column(children: [
Center(
child: Container(
width: MediaQuery.of(context).size.width,
color: Theme.of(context).cardColor,
child: TabBar(
padding: EdgeInsets.symmetric(
horizontal: Dimensions.PADDING_SIZE_EXTRA_LARGE),
controller: _tabController,
labelColor: Theme.of(context).primaryColor,
unselectedLabelColor: Theme.of(context).hintColor,
indicatorColor: Theme.of(context).primaryColor,
indicatorWeight: 1,
unselectedLabelStyle: robotoRegular.copyWith(
fontSize: Dimensions.FONT_SIZE_DEFAULT,
fontWeight: FontWeight.w400,
),
labelStyle: robotoRegular.copyWith(
fontSize: Dimensions.FONT_SIZE_DEFAULT,
fontWeight: FontWeight.w700,
),
tabs: [
Tab(text: getTranslated("seller_info", context)),
Tab(text: getTranslated("shop_info", context)),
Tab(text: getTranslated("verification", context))
],
),
),
),
SizedBox(
height: Dimensions.PADDING_SIZE_SMALL,
),
Expanded(
child: TabBarView(
controller: _tabController,
children: [
InfoFieldVIew(
pageIndex: 1,
),
InfoFieldVIew(
pageIndex: 2,
),
InfoFieldVIew(
pageIndex: 3,
),
],
)),
]);
}),
bottomNavigationBar:
Consumer<AuthProvider>(builder: (context, authProvider, _) {
print('tab index is ====>${_tabController.index}/$selectedIndex');
return Container(
height: 70,
padding: EdgeInsets.all(Dimensions.PADDING_SIZE_SMALL),
decoration: BoxDecoration(color: Theme.of(context).cardColor),
child: (authProvider.selectionTabIndex == 0)
? CustomButton(
btnTxt: getTranslated('next', context),
onTap: () {
if (authProvider.firstNameController.text.trim().isEmpty) {
showCustomSnackBar(
getTranslated('first_name_is_required', context),
context);
} else if (authProvider.lastNameController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated('last_name_is_required', context),
context);
} else if (authProvider.emailController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated('email_is_required', context), context);
} else if (EmailChecker.isNotValid(
authProvider.emailController.text.trim())) {
showCustomSnackBar(
getTranslated('email_is_ot_valid', context), context);
} else if (authProvider.phoneController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated('phone_is_required', context), context);
} else if (authProvider.phoneController.text.trim().length <
8) {
showCustomSnackBar(
getTranslated('phone_number_is_not_valid', context),
context);
} else if (authProvider.passwordController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated('password_is_required', context),
context);
} else if (authProvider.passwordController.text
.trim()
.length <
8) {
showCustomSnackBar(
getTranslated(
'password_minimum_length_is_6', context),
context);
} else if (authProvider.confirmPasswordController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'confirm_password_is_required', context),
context);
} else if (authProvider.passwordController.text.trim() !=
authProvider.confirmPasswordController.text.trim()) {
showCustomSnackBar(
getTranslated('password_is_mismatch', context),
context);
} else if (authProvider.sellerProfileImage == null) {
showCustomSnackBar(
getTranslated('profile_image_is_required', context),
context);
} else if (authProvider.sellerCniRecto == null) {
showCustomSnackBar(
getTranslated('cni_recto_is_required', context),
context);
} else if (authProvider.sellerCniVerso == null) {
showCustomSnackBar(
getTranslated('cni_verso_is_required', context),
context);
} else {
_tabController.animateTo((_tabController.index + 1) % 2);
selectedIndex = _tabController.index + 1;
authProvider.setIndexForTabBar(selectedIndex);
print(authProvider.selectionTabIndex);
}
},
)
: (authProvider.selectionTabIndex == 1)
? Row(
children: [
Container(
width: 120,
child: CustomButton(
btnTxt: getTranslated('back', context),
backgroundColor: Theme.of(context).hintColor,
isColor: true,
onTap: () {
_tabController
.animateTo((_tabController.index + 1) % 2);
selectedIndex = _tabController.index - 1;
authProvider.setIndexForTabBar(selectedIndex);
print(authProvider.selectionTabIndex);
},
),
),
SizedBox(width: Dimensions.PADDING_SIZE_SMALL),
authProvider.isLoading
? CircularProgressIndicator()
: Expanded(
child: CustomButton(
btnTxt: getTranslated('next', context),
onTap: !authProvider.isTermsAndCondition
? null
: () {
if (authProvider
.firstNameController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'first_name_is_required',
context),
context);
} else if (authProvider
.lastNameController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'last_name_is_required',
context),
context);
} else if (authProvider
.emailController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'email_is_required',
context),
context);
} else if (EmailChecker.isNotValid(
authProvider.emailController.text
.trim())) {
showCustomSnackBar(
getTranslated(
'email_is_ot_valid',
context),
context);
} else if (authProvider
.phoneController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'phone_is_required',
context),
context);
} else if (authProvider
.phoneController.text
.trim()
.length <
8) {
showCustomSnackBar(
getTranslated(
'phone_number_is_not_valid',
context),
context);
} else if (authProvider
.passwordController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'password_is_required',
context),
context);
} else if (authProvider
.passwordController.text
.trim()
.length <
8) {
showCustomSnackBar(
getTranslated(
'password_minimum_length_is_6',
context),
context);
} else if (authProvider
.confirmPasswordController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'confirm_password_is_required',
context),
context);
} else if (authProvider
.passwordController.text
.trim() !=
authProvider
.confirmPasswordController
.text
.trim()) {
showCustomSnackBar(
getTranslated(
'password_is_mismatch',
context),
context);
} else if (authProvider
.shopNameController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'shop_name_is_required',
context),
context);
} else if (authProvider
.shopAddressController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'shop_address_is_required',
context),
context);
} else if (authProvider.shopLogo ==
null) {
showCustomSnackBar(
getTranslated(
'shop_logo_is_required',
context),
context);
} else if (authProvider.shopBanner ==
null) {
showCustomSnackBar(
getTranslated(
'shop_banner_is_required',
context),
context);
} else if (authProvider
.shopLocalizedPosition ==
null ||
authProvider
.shopLocalizedAdress ==
null) {
showCustomSnackBar(
getTranslated(
'locate_shop_before',
context),
context);
} else {
_tabController.animateTo(
(_tabController.index + 1) % 3);
selectedIndex =
_tabController.index + 1;
authProvider.setIndexForTabBar(
selectedIndex);
print(
authProvider.selectionTabIndex);
}
},
),
),
],
)
: Row(
children: [
Container(
width: 120,
child: CustomButton(
btnTxt: getTranslated('back', context),
backgroundColor: Theme.of(context).hintColor,
isColor: true,
onTap: () {
_tabController
.animateTo((_tabController.index + 1) % 2);
selectedIndex = _tabController.index - 1;
authProvider.setIndexForTabBar(selectedIndex);
print(authProvider.selectionTabIndex);
},
),
),
SizedBox(width: Dimensions.PADDING_SIZE_SMALL),
Expanded(
child: authProvider.isLoading
? CircularProgressIndicator(
color: ColorResources.PRIMARY,
)
: CustomButton(
btnTxt: getTranslated('submit', context),
onTap: !authProvider.isTermsAndCondition
? null
: () {
if (authProvider
.firstNameController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'first_name_is_required',
context),
context);
} else if (authProvider
.lastNameController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'last_name_is_required',
context),
context);
} else if (authProvider
.emailController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'email_is_required',
context),
context);
} else if (EmailChecker.isNotValid(
authProvider.emailController.text
.trim())) {
showCustomSnackBar(
getTranslated(
'email_is_ot_valid',
context),
context);
} else if (authProvider
.phoneController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'phone_is_required',
context),
context);
} else if (authProvider
.phoneController.text
.trim()
.length <
8) {
showCustomSnackBar(
getTranslated(
'phone_number_is_not_valid',
context),
context);
} else if (authProvider
.passwordController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'password_is_required',
context),
context);
} else if (authProvider
.passwordController.text
.trim()
.length <
8) {
showCustomSnackBar(
getTranslated(
'password_minimum_length_is_6',
context),
context);
} else if (authProvider
.confirmPasswordController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'confirm_password_is_required',
context),
context);
} else if (authProvider
.passwordController.text
.trim() !=
authProvider
.confirmPasswordController
.text
.trim()) {
showCustomSnackBar(
getTranslated(
'password_is_mismatch',
context),
context);
} else if (authProvider
.shopNameController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'shop_name_is_required',
context),
context);
} else if (authProvider
.shopAddressController.text
.trim()
.isEmpty) {
showCustomSnackBar(
getTranslated(
'shop_address_is_required',
context),
context);
} else if (authProvider.shopLogo ==
null) {
showCustomSnackBar(
getTranslated(
'shop_logo_is_required',
context),
context);
} else if (authProvider.shopBanner ==
null) {
showCustomSnackBar(
getTranslated(
'shop_banner_is_required',
context),
context);
} else if (authProvider
.shopLocalizedPosition ==
null ||
authProvider
.shopLocalizedAdress ==
null) {
showCustomSnackBar(
getTranslated(
'locate_shop_before',
context),
context);
} else if (authProvider
.rccmController.text.length <=
15) {
showCustomSnackBar(
getTranslated(
'invalid_rccm', context),
context);
} else if (authProvider
.ifuController.text.isEmpty) {
showCustomSnackBar(
getTranslated(
'ifu_is_required', context),
context);
} else if (authProvider.sellerRccm ==
null) {
showCustomSnackBar(
getTranslated(
'rccm_photo_is_required',
context),
context);
} else if (authProvider.sellerIfu ==
null) {
showCustomSnackBar(
getTranslated(
'ifu_photo_is_required',
context),
context);
} else {
RegisterModel registerModel =
RegisterModel(
fName: authProvider
.firstNameController.text
.trim(),
lName: authProvider
.lastNameController.text
.trim(),
phone: authProvider
.phoneController.text
.trim(),
email: authProvider
.emailController.text
.trim(),
password: authProvider
.passwordController.text
.trim(),
confirmPassword: authProvider
.confirmPasswordController
.text
.trim(),
shopName: authProvider
.shopNameController.text
.trim(),
shopAddress: authProvider
.shopAddressController.text
.trim(),
location: authProvider.location,
rccm: authProvider
.rccmController.text
.trim(),
ifu: authProvider
.ifuController.text
.trim(),
);
authProvider
.registration(
context, registerModel)
.then((value) {
if (value.response.statusCode ==
200) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (BuildContext
context) =>
SuccessfullyRegisteredScreen()));
}
});
}
},
),
),
],
),
);
}),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment