Skip to content

Commit

Permalink
addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
mo7amedaliEbaid committed Dec 22, 2023
1 parent c7a9d3c commit efc93fc
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 127 deletions.
16 changes: 8 additions & 8 deletions lib/core/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class MyApp extends StatelessWidget {
create: (context) => di.sl<DeliveryInfoActionCubit>(),
),
BlocProvider(
lazy: false,
create: (context) =>
di.sl<DeliveryInfoFetchCubit>()..fetchDeliveryInfo(),
),
Expand All @@ -67,8 +68,8 @@ class MyApp extends StatelessWidget {
BlocProvider(
create: (context) => di.sl<ShareCubit>(),
),
BlocProvider(
lazy: false,
BlocProvider(
lazy: false,
create: (context) => di.sl<NotificationsCubit>()..init(),
),
],
Expand Down Expand Up @@ -96,12 +97,11 @@ class MyApp extends StatelessWidget {
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
)
),
style: OutlinedButton.styleFrom(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
)),
iconTheme: const IconThemeData(color: AppColors.CommonCyan, size: 30),
floatingActionButtonTheme: const FloatingActionButtonThemeData(
backgroundColor: AppColors.CommonCyan,
Expand Down
8 changes: 4 additions & 4 deletions lib/core/router/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sealed class AppRouter {
static const String filter = '/filter';
static const String signup = '/signup';
static const String login = '/login';
static const String adress = '/adress';
static const String addresses = '/addresses';
static const String addadress = '/addadress';
static const String checkout = '/checkout';
static const String contact = '/contact';
Expand Down Expand Up @@ -68,12 +68,12 @@ sealed class AppRouter {
return MaterialPageRoute(builder: (_) => ContactScreen());
case cart:
return MaterialPageRoute(builder: (_) => const CartScreen());
case adress:
return MaterialPageRoute(builder: (_) => const AdressScreen());
case addresses:
return MaterialPageRoute(builder: (_) => const AddressesScreen());
case addadress:
DeliveryInfo? deliveryInfo = routeSettings.arguments as DeliveryInfo?;
return MaterialPageRoute(
builder: (_) => AddAdressScreen(
builder: (_) => AddAddressScreen(
deliveryInfo: deliveryInfo,
));
case checkout:
Expand Down
109 changes: 66 additions & 43 deletions lib/presentation/screens/add_edit_address.dart
Original file line number Diff line number Diff line change
@@ -1,57 +1,68 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_phoenix/flutter_phoenix.dart';
import 'package:piiicks/configs/configs.dart';
import 'package:piiicks/core/router/app_router.dart';
import 'package:piiicks/presentation/widgets/custom_appbar.dart';
import 'package:piiicks/presentation/widgets/mobile_number_textfield.dart';
import 'package:piiicks/presentation/widgets/textfield_toptext.dart';

import '../../application/delivery_info_action_cubit/delivery_info_action_cubit.dart';
import '../../application/delivery_info_fetch_cubit/delivery_info_fetch_cubit.dart';
import '../../application/notifications_cubit/notifications_cubit.dart';
import '../../core/router/app_router.dart';
import '../../data/models/delivery/delivery_info_model.dart';
import '../../domain/entities/delivery/delivery_info.dart';
import '../widgets/custom_textfield.dart';

class AddAdressScreen extends StatefulWidget {
class AddAddressScreen extends StatefulWidget {
final DeliveryInfo? deliveryInfo;

const AddAdressScreen({
const AddAddressScreen({
super.key,
this.deliveryInfo,
});

@override
State<AddAdressScreen> createState() => _AddAdressScreenState();
State<AddAddressScreen> createState() => _AddAddressScreenState();
}

class _AddAdressScreenState extends State<AddAdressScreen> {
class _AddAddressScreenState extends State<AddAddressScreen> {
String? id;
final TextEditingController firstName = TextEditingController();
final TextEditingController lastName = TextEditingController();
final TextEditingController addressLineOne = TextEditingController();
final TextEditingController addressLineTwo = TextEditingController();
final TextEditingController city = TextEditingController();
final TextEditingController zipCode = TextEditingController();
final TextEditingController contactNumber = TextEditingController();
final TextEditingController _firstName = TextEditingController();
final TextEditingController _lastName = TextEditingController();
final TextEditingController _addressLineOne = TextEditingController();
final TextEditingController _addressLineTwo = TextEditingController();
final TextEditingController _city = TextEditingController();
final TextEditingController _zipCode = TextEditingController();
final TextEditingController _contactNumber = TextEditingController();
final _formKey = GlobalKey<FormState>();

@override
void initState() {
if (widget.deliveryInfo != null) {
id = widget.deliveryInfo!.id;
firstName.text = widget.deliveryInfo!.firstName;
lastName.text = widget.deliveryInfo!.lastName;
addressLineOne.text = widget.deliveryInfo!.addressLineOne;
addressLineTwo.text = widget.deliveryInfo!.addressLineTwo;
city.text = widget.deliveryInfo!.city;
zipCode.text = widget.deliveryInfo!.zipCode;
contactNumber.text = widget.deliveryInfo!.contactNumber;
_firstName.text = widget.deliveryInfo!.firstName;
_lastName.text = widget.deliveryInfo!.lastName;
_addressLineOne.text = widget.deliveryInfo!.addressLineOne;
_addressLineTwo.text = widget.deliveryInfo!.addressLineTwo;
_city.text = widget.deliveryInfo!.city;
_zipCode.text = widget.deliveryInfo!.zipCode;
_contactNumber.text = widget.deliveryInfo!.contactNumber;
}
super.initState();
}

@override
void dispose() {
_firstName.dispose();
_lastName.dispose();
_addressLineOne.dispose();
_addressLineTwo.dispose();
_city.dispose();
_zipCode.dispose();
_contactNumber.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -81,19 +92,19 @@ class _AddAdressScreenState extends State<AddAdressScreen> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFieldTopText("First Name*"),
buildTextFormField(firstName, 'First name'),
buildTextFormField(_firstName, 'First name'),
TextFieldTopText("Last name*"),
buildTextFormField(lastName, 'Last name'),
buildTextFormField(_lastName, 'Last name'),
TextFieldTopText("Line One*"),
buildTextFormField(addressLineOne, 'Address line one'),
buildTextFormField(_addressLineOne, 'Address line one'),
TextFieldTopText("Line Two*"),
buildTextFormField(addressLineTwo, 'Address line two'),
buildTextFormField(_addressLineTwo, 'Address line two'),
TextFieldTopText("City*"),
buildTextFormField(city, 'City'),
buildTextFormField(_city, 'City'),
TextFieldTopText("Zip Code*"),
buildTextFormField(zipCode, 'Zip code'),
buildTextFormField(_zipCode, 'Zip code'),
TextFieldTopText("Contact number*"),
MobileNumberTextField(contactNumber, 'Contact number'),
MobileNumberTextField(_contactNumber, 'Contact number'),
Space.yf(2),
SizedBox(
width: double.infinity,
Expand All @@ -105,37 +116,49 @@ class _AddAdressScreenState extends State<AddAdressScreen> {
.read<DeliveryInfoActionCubit>()
.addDeliveryInfo(DeliveryInfoModel(
id: '',
firstName: firstName.text,
lastName: lastName.text,
addressLineOne: addressLineOne.text,
addressLineTwo: addressLineTwo.text,
city: city.text,
zipCode: zipCode.text,
contactNumber: contactNumber.text,
firstName: _firstName.text,
lastName: _lastName.text,
addressLineOne: _addressLineOne.text,
addressLineTwo: _addressLineTwo.text,
city: _city.text,
zipCode: _zipCode.text,
contactNumber: _contactNumber.text,
));
context
.read<NotificationsCubit>()
.showAndSaveNotification("Addresses Update",
"Congratulations, You have successfully updated your Address Book.");
Phoenix.rebirth(context);
// Phoenix.rebirth(context);
context
.read<DeliveryInfoFetchCubit>()
.fetchDeliveryInfo();
Navigator.pop(context);

Navigator.of(context)
.popAndPushNamed(AppRouter.addresses);
} else {
context
.read<DeliveryInfoActionCubit>()
.editDeliveryInfo(DeliveryInfoModel(
id: id!,
firstName: firstName.text,
lastName: lastName.text,
addressLineOne: addressLineOne.text,
addressLineTwo: addressLineTwo.text,
city: city.text,
zipCode: zipCode.text,
contactNumber: contactNumber.text,
firstName: _firstName.text,
lastName: _lastName.text,
addressLineOne: _addressLineOne.text,
addressLineTwo: _addressLineTwo.text,
city: _city.text,
zipCode: _zipCode.text,
contactNumber: _contactNumber.text,
));
context
.read<NotificationsCubit>()
.showAndSaveNotification("Addresses Update",
"Congratulations, You have successfully updated your Address Book.");
Phoenix.rebirth(context);
// Phoenix.rebirth(context);
context
.read<DeliveryInfoFetchCubit>()
.fetchDeliveryInfo();
Navigator.pop(context);
// Navigator.of(context).popAndPushNamed(AppRouter.addresses);
}
}
},
Expand Down
17 changes: 12 additions & 5 deletions lib/presentation/screens/addresses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ import '../../application/delivery_info_action_cubit/delivery_info_action_cubit.
import '../../application/delivery_info_fetch_cubit/delivery_info_fetch_cubit.dart';
import '../widgets/adress_card.dart';

class AdressScreen extends StatefulWidget {
const AdressScreen({Key? key}) : super(key: key);
class AddressesScreen extends StatefulWidget {
const AddressesScreen({Key? key}) : super(key: key);

@override
State<AdressScreen> createState() => _AdressScreenState();
State<AddressesScreen> createState() => _AddressesScreenState();
}

class _AdressScreenState extends State<AdressScreen> {
class _AddressesScreenState extends State<AddressesScreen> {
@override
void initState() {
context.read<DeliveryInfoFetchCubit>().fetchDeliveryInfo();
super.initState();
}

@override
Widget build(BuildContext context) {
return BlocListener<DeliveryInfoActionCubit, DeliveryInfoActionState>(
Expand All @@ -33,7 +39,8 @@ class _AdressScreenState extends State<AdressScreen> {
}
},
child: Scaffold(
appBar: CustomAppBar("ADD ADDRESS", context,automaticallyImplyLeading: true),
appBar: CustomAppBar("ADD ADDRESS", context,
automaticallyImplyLeading: true),
body: Padding(
padding: Space.all(1.2, 1),
child: Column(
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/screens/checkout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class _CheckOutScreenState extends State<CheckOutScreen> {
context: context,
onTap: () {
Navigator.of(context)
.pushNamed(AppRouter.adress);
.pushNamed(AppRouter.addresses);
},
buttonText: "Add Address")
],
Expand Down
66 changes: 35 additions & 31 deletions lib/presentation/screens/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _LoginScreenState extends State<LoginScreen> {
final TextEditingController _passwordController = TextEditingController();
final _formKey = GlobalKey<FormState>();

bool isLoading = false;
/* bool isLoading = false;
void _startLoading() {
setState(() {
isLoading = true;
Expand All @@ -39,10 +39,16 @@ class _LoginScreenState extends State<LoginScreen> {
isLoading = false;
});
});
}*/

@override
void dispose() {
_emailController.dispose();
_passwordController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {

return Scaffold(
appBar: CustomAppBar("LOGIN", context, automaticallyImplyLeading: true),
body: SingleChildScrollView(
Expand Down Expand Up @@ -88,13 +94,9 @@ class _LoginScreenState extends State<LoginScreen> {
],
),
Space.yf(1.7),
BlocListener<UserBloc, UserState>(
BlocConsumer<UserBloc, UserState>(
listener: (context, state) {
if (state is UserLoading) {
setState(() {
_startLoading();
});
} else if (state is UserLogged) {
if (state is UserLogged) {
showSuccessfulAuthDialog(context, "logged in");
} else if (state is UserLoggedFail) {
if (state.failure is CredentialFailure) {
Expand All @@ -104,32 +106,34 @@ class _LoginScreenState extends State<LoginScreen> {
}
}
},
child: ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
context.read<UserBloc>().add(
SignInUser(
SignInParams(
username: _emailController.text,
password: _passwordController.text,
builder: (context, state) {
return ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
context.read<UserBloc>().add(
SignInUser(
SignInParams(
username: _emailController.text,
password: _passwordController.text,
),
),
),
);
}
},
style: ButtonStyle(
minimumSize: MaterialStatePropertyAll(
Size(
double.infinity,
AppDimensions.normalize(20),
);
}
},
style: ButtonStyle(
minimumSize: MaterialStatePropertyAll(
Size(
double.infinity,
AppDimensions.normalize(20),
),
),
),
),
child: Text(
isLoading == true ? "Wait..." : "Login",
style: AppText.h3b?.copyWith(color: Colors.white),
),
),
child: Text(
(state is UserLoading) ? "Wait..." : "Login",
style: AppText.h3b?.copyWith(color: Colors.white),
),
);
},
),
Space.yf(1.5),
Center(
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/screens/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ProfileScreen extends StatelessWidget {
GestureDetector(
onTap: () {
Navigator.of(context)
.pushNamed(AppRouter.adress);
.pushNamed(AppRouter.addresses);
},
child: Row(
mainAxisAlignment:
Expand Down
Loading

0 comments on commit efc93fc

Please sign in to comment.