-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from ia-toki/110-revamp-authentication
110 revamp authentication
- Loading branch information
Showing
5 changed files
with
378 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
279 changes: 279 additions & 0 deletions
279
app/lib/features/onboarding/presentation/pages/v2/register_page.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
part of '_pages.dart'; | ||
|
||
class RegisterPageV2 extends StatefulWidget { | ||
const RegisterPageV2({super.key, this.isUpdateProfile}); | ||
|
||
final String? isUpdateProfile; | ||
|
||
@override | ||
State<RegisterPageV2> createState() => _RegisterPageV2State(); | ||
} | ||
|
||
class _RegisterPageV2State extends State<RegisterPageV2> { | ||
late final UserRegisterBloc _userRegisterBloc; | ||
String? selectedValue; | ||
|
||
@override | ||
void initState() { | ||
_userRegisterBloc = get<UserRegisterBloc>(); | ||
|
||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final size = MediaQuery.of(context).size; | ||
return BlocProvider( | ||
create: (_) => get<UserRegisterBloc>() | ||
..add( | ||
const InitialValueEvent(), | ||
), | ||
child: BlocListener<UserRegisterBloc, RegisterFormState>( | ||
listener: (context, state) { | ||
if (state is UserRegisterSuccessState) { | ||
if (widget.isUpdateProfile == 'true') { | ||
Navigator.pop(context); | ||
|
||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => | ||
const RegisterPageV2(isUpdateProfile: 'true'), | ||
), | ||
); | ||
|
||
context.read<HomeCubit>().fetchUser(); | ||
|
||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text('Pembaruan data profil berhasil'), | ||
behavior: SnackBarBehavior.floating, | ||
), | ||
); | ||
} else { | ||
context.go('/main'); | ||
} | ||
} | ||
}, | ||
child: BlocBuilder<UserRegisterBloc, RegisterFormState>( | ||
builder: (context, state) { | ||
return BebrasScaffold( | ||
avoidBottomInset: false, | ||
body: SizedBox( | ||
height: double.infinity, | ||
child: Form( | ||
key: state.formKey, | ||
child: Stack( | ||
children: [ | ||
Container( | ||
height: 200, | ||
width: double.infinity, | ||
decoration: const BoxDecoration( | ||
color: Color(0xFF1BB8E1), | ||
borderRadius: BorderRadius.only( | ||
bottomLeft: Radius.circular(60), | ||
bottomRight: Radius.circular(60), | ||
), | ||
), | ||
), | ||
Positioned( | ||
top: 100, | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
child: Container( | ||
padding: const EdgeInsets.symmetric(horizontal: 20), | ||
decoration: const BoxDecoration( | ||
color: Colors.white, | ||
borderRadius: BorderRadius.only( | ||
topLeft: Radius.circular(42.0), | ||
topRight: Radius.circular(42.0), | ||
), | ||
), | ||
child: BlocBuilder<UserRegisterBloc, RegisterFormState>( | ||
builder: (context, state) { | ||
return Column( | ||
children: [ | ||
const SizedBox( | ||
height: 40, | ||
), | ||
Align( | ||
alignment: Alignment.centerLeft, | ||
child: Text( | ||
'Ayo isi data diri kamu!', | ||
style: FontTheme.blackSubtitleBold(), | ||
), | ||
), | ||
const SizedBox( | ||
height: 30, | ||
), | ||
Container( | ||
margin: const EdgeInsets.only(bottom: 5), | ||
child: const Align( | ||
alignment: Alignment.centerLeft, | ||
child: Text( | ||
'Email', | ||
style: TextStyle( | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
), | ||
), | ||
CustomTextField( | ||
(value) { | ||
BlocProvider.of<UserRegisterBloc>(context).add( | ||
EmailEvent(email: BlocFormItem(value: value)), | ||
); | ||
}, | ||
(val) { | ||
return state.email.error; | ||
}, | ||
state.email.value, | ||
), | ||
Container( | ||
margin: const EdgeInsets.only(bottom: 5), | ||
child: const Align( | ||
alignment: Alignment.centerLeft, | ||
child: Text( | ||
'Nama', | ||
style: TextStyle( | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
), | ||
), | ||
CustomTextField( | ||
(value) { | ||
BlocProvider.of<UserRegisterBloc>(context).add( | ||
NameEvent(name: BlocFormItem(value: value)), | ||
); | ||
}, | ||
(val) { | ||
return state.name.error; | ||
}, | ||
state.email.value, | ||
), | ||
Container( | ||
margin: const EdgeInsets.only(bottom: 5), | ||
child: const Align( | ||
alignment: Alignment.centerLeft, | ||
child: Text( | ||
'Sekolah', | ||
style: TextStyle( | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
), | ||
), | ||
CustomTextField( | ||
(value) { | ||
BlocProvider.of<UserRegisterBloc>(context).add( | ||
SchoolEvent(school: BlocFormItem(value: value)), | ||
); | ||
}, | ||
(val) { | ||
return state.school.error; | ||
}, | ||
state.email.value, | ||
), | ||
Container( | ||
margin: const EdgeInsets.only(bottom: 5), | ||
child: const Align( | ||
alignment: Alignment.centerLeft, | ||
child: Text( | ||
'Provinsi', | ||
style: TextStyle( | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
), | ||
), | ||
ProvinceDropdown( | ||
(value) { | ||
BlocProvider.of<UserRegisterBloc>(context).add( | ||
ProvinceEvent( | ||
province: BlocFormItem( | ||
value: value, | ||
), | ||
), | ||
); | ||
}, | ||
(val) { | ||
return state.province.error; | ||
}, | ||
state.province.value.isNotEmpty | ||
? state.province.value | ||
: 'Provinsi', | ||
), | ||
const SizedBox(height: 20), | ||
BlocConsumer<UserRegisterBloc, RegisterFormState>( | ||
bloc: _userRegisterBloc, | ||
listener: (context, state) { | ||
if (state is UserRegisterSuccessState) { | ||
if (widget.isUpdateProfile == 'true') { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar( | ||
content: const Text( | ||
'Profile data successfully updated', | ||
), | ||
action: SnackBarAction( | ||
label: 'OK', | ||
onPressed: () { | ||
// Some code to undo the change. | ||
}, | ||
), | ||
), | ||
); | ||
} else { | ||
context.go('/main'); | ||
} | ||
} | ||
}, | ||
builder: (context, state) { | ||
return ElevatedButton( | ||
style: ElevatedButton.styleFrom( | ||
fixedSize: Size(size.width, 45), | ||
backgroundColor: const Color(0xFF1BB8E1), | ||
foregroundColor: Colors.white, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(10), | ||
), | ||
), | ||
onPressed: () { | ||
if (state is! UserRegisterLoadingState) { | ||
if (widget.isUpdateProfile == 'true') { | ||
BlocProvider.of<UserRegisterBloc>(context) | ||
.add(const FormSubmitUpdateEvent()); | ||
} else { | ||
BlocProvider.of<UserRegisterBloc>(context) | ||
.add(const FormSubmitEvent()); | ||
} | ||
} | ||
}, | ||
child: Text( | ||
widget.isUpdateProfile == 'true' | ||
? 'Perbarui' | ||
: 'Daftar', | ||
style: | ||
const TextStyle(fontWeight: FontWeight.w600), | ||
), | ||
); | ||
}, | ||
), | ||
], | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/lib/features/onboarding/presentation/pages/v2/widgets/custom_text_field.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class CustomTextField extends StatelessWidget { | ||
const CustomTextField( | ||
this.handleTextInput, | ||
this.validator, | ||
this.initValue, { | ||
super.key, | ||
}); | ||
|
||
final void Function(String value)? handleTextInput; | ||
final String? Function(String?)? validator; | ||
final String? initValue; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
height: 60, | ||
child: TextFormField( | ||
onChanged: (value) => handleTextInput!(value), | ||
validator: validator, | ||
initialValue: initValue, | ||
style: const TextStyle(fontSize: 12), | ||
decoration: InputDecoration( | ||
helperText: '', | ||
helperStyle: const TextStyle(fontSize: 10), | ||
filled: true, | ||
fillColor: Colors.grey.shade200, | ||
enabledBorder: OutlineInputBorder( | ||
borderSide: BorderSide(color: Colors.grey.shade200), | ||
), | ||
focusedBorder: OutlineInputBorder( | ||
borderSide: BorderSide(color: Colors.grey.shade400), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
app/lib/features/onboarding/presentation/pages/v2/widgets/province_dropdown.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:dropdown_search/dropdown_search.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../../../../../core/constants/indonesia_province.dart'; | ||
|
||
class ProvinceDropdown extends StatelessWidget { | ||
const ProvinceDropdown( | ||
this.handleTextInput, | ||
this.validator, | ||
this.initValue, { | ||
super.key, | ||
}); | ||
|
||
final void Function(String value)? handleTextInput; | ||
final String? Function(String?)? validator; | ||
final String? initValue; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
height: 63, | ||
child: DropdownSearch<String>( | ||
selectedItem: initValue, | ||
validator: validator, | ||
popupProps: const PopupProps.menu( | ||
showSearchBox: true, | ||
), | ||
items: provinceList, | ||
dropdownDecoratorProps: DropDownDecoratorProps( | ||
textAlignVertical: TextAlignVertical.center, | ||
baseStyle: const TextStyle(fontSize: 12), | ||
dropdownSearchDecoration: InputDecoration( | ||
helperText: '', | ||
helperStyle: const TextStyle(fontSize: 10), | ||
filled: true, | ||
fillColor: Colors.grey.shade200, | ||
enabledBorder: UnderlineInputBorder( | ||
borderSide: BorderSide(color: Colors.grey.shade200), | ||
), | ||
focusedBorder: UnderlineInputBorder( | ||
borderSide: BorderSide(color: Colors.grey.shade400), | ||
), | ||
), | ||
), | ||
onChanged: (String? item) => handleTextInput!(item!), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.