Skip to content

Commit

Permalink
Merge pull request #159 from ia-toki/110-revamp-authentication
Browse files Browse the repository at this point in the history
110 revamp authentication
  • Loading branch information
gmochid authored Apr 2, 2024
2 parents 9e1947f + e84b69c commit 393f42c
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/lib/features/onboarding/presentation/pages/v2/_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import 'package:page_view_indicators/circle_page_indicator.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../../../../core/bases/widgets/atoms/button.dart';
import '../../../../authentication/register/bloc/user_register_bloc.dart';
import '../../../../authentication/register/model/form_item.dart';
import '../../../../../core/bases/widgets/layout/bebras_scaffold.dart';
import '../../../../../core/constants/assets.dart';
import '../../../../../core/constants/get_started.dart';
import '../../../../../core/theme/base_colors.dart';
import '../../../../../core/theme/font_theme.dart';
import '../../../../../services/di.dart';
import '../../../../main/presentation/bloc/home_cubit.dart';
import '../../bloc/user_initialization_bloc.dart';
import './widgets/custom_text_field.dart';
import './widgets/province_dropdown.dart';

part 'onboarding_page.dart';
part 'splash_screen.dart';
part 'update_dialog.dart';
part 'register_page.dart';
279 changes: 279 additions & 0 deletions app/lib/features/onboarding/presentation/pages/v2/register_page.dart
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),
),
);
},
),
],
);
},
),
),
),
],
),
),
),
);
},
),
),
);
}
}
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),
),
),
),
);
}
}
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!),
),
);
}
}
Loading

0 comments on commit 393f42c

Please sign in to comment.