Initial commit

This commit is contained in:
jahongireshonqulov
2025-10-17 19:42:02 +05:00
commit 9fbdabafb4
1420 changed files with 28021 additions and 0 deletions

View File

@@ -0,0 +1,459 @@
import 'package:flutter/material.dart';
import 'package:grostore/app_lang.dart';
import 'package:grostore/configs/style_config.dart';
import 'package:grostore/configs/theme_config.dart';
import 'package:grostore/custom_ui/BoxDecorations.dart';
import 'package:grostore/custom_ui/Button.dart';
import 'package:grostore/custom_ui/common_appbar.dart';
import 'package:grostore/custom_ui/input_decorations.dart';
import 'package:grostore/custom_ui/toast_ui.dart';
import 'package:grostore/helpers/device_info_helper.dart';
import 'package:grostore/helpers/route.dart';
import 'package:grostore/models/city_response.dart';
import 'package:grostore/models/country_response.dart';
import 'package:grostore/models/state_response.dart';
import 'package:grostore/presenters/address_presenter.dart';
import 'package:grostore/screens/address/addresses.dart';
import 'package:grostore/screens/profile.dart';
class AddressNewOrUpdate extends StatefulWidget {
int? addressId;
AddressNewOrUpdate({super.key, this.addressId});
@override
State<AddressNewOrUpdate> createState() => _AddressNewOrUpdateState();
}
class _AddressNewOrUpdateState extends State<AddressNewOrUpdate> {
AddressPresenter addressPresenter = AddressPresenter();
@override
void initState() {
// TODO: implement initState
if (widget.addressId != null) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
addressPresenter.getEditAddressData(widget.addressId, context);
});
}else{
addressPresenter.getCountries();
}
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CommonAppbar.show(
title: widget.addressId == null
? AppLang.local(context).add_new_address_ucf
: AppLang.local(context).update_address,
context: context),
body: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(StyleConfig.padding),
child: ListenableBuilder(
listenable: addressPresenter,
builder: (context, child) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//buildLabelText(AppLang.local(context).country),
space(size: 10),
// buildButton(AppLang.local(context).select_country,
// addressPresenter.selectedCountry?.name ?? "", () {
// showCountryDialog();
// }),
countryDropDown(),
space(),
//buildLabelText(AppLang.local(context).state),
//space(size: 10),
// buildButton(AppLang.local(context).select_state,
// addressPresenter.selectedState?.name ?? '', () {
// if (addressPresenter.selectedCountry != null) {
// showStateDialog();
// } else {
// ToastUi.show(context,
// AppLang.local(context).please_select_a_country);
// }
// }),
stateDropDown(),
space(),
// buildLabelText(AppLang.local(context).city),
// space(size: 10),
// buildButton(AppLang.local(context).select_city,
// addressPresenter.selectedCity?.name ?? '', () {
// if (addressPresenter.selectedState != null) {
// showCityDialog();
// } else {
// ToastUi.show(context,
// AppLang.local(context).please_select_a_state);
// }
// }),
cityDropDown(),
space(),
isDefaultDropDown(),
space(),
Container(
height: 100,
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 10),
decoration: BoxDecorations.customRadius(
radius: BorderRadius.circular(8))
.copyWith(
border: Border.all(color: ThemeConfig.grey)),
child: TextField(
controller: addressPresenter.addressController,
decoration: const InputDecoration.collapsed(
hintText: "2/5 Elephant Road, New Town"),
),
),
space(),
Button(
onPressed: () {
if (widget.addressId != null) {
addressPresenter.updateAddress(context,
id: widget.addressId!,
countryInfo: addressPresenter.selectedCountry,
stateInfo: addressPresenter.selectedState,
cityInfo: addressPresenter.selectedCity,
fullAddress: addressPresenter.addressController.text.trim(),
isDefault:
addressPresenter.defaultAddress == "No"
? 0
: 1);
} else {
addressPresenter.addAddress(context,
countryInfo: addressPresenter.selectedCountry,
stateInfo: addressPresenter.selectedState,
cityInfo: addressPresenter.selectedCity,
fullAddress: addressPresenter
.addressController.text
.trim(),
isDefault:
addressPresenter.defaultAddress == "No"
? 0
: 1);
}
Navigator.of(context).pop();
},
shape: StyleConfig.buttonRadius(8),
color: ThemeConfig.red,
minWidth: getWidth(context),
minHeight: 40.0,
child: Text(
AppLang.local(context).save,
style: StyleConfig.fs14cWhitefwBold,
))
],
);
}),
),
),
);
}
Text buildLabelText(String text) => Text(
text,
style: StyleConfig.fs14fwBold,
);
Widget space({size = 24}) {
return SizedBox(
height: size.toDouble(),
);
}
Button buildButton(String title, value, onPress) {
return Button(
onPressed: () => onPress(),
color: ThemeConfig.grey,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(8), topLeft: Radius.circular(8))),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
width: 120,
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
decoration: BoxDecorations.customRadius(
radius: const BorderRadius.only(
bottomLeft: Radius.circular(8),
topLeft: Radius.circular(8)),
color: ThemeConfig.secondaryColor),
child: Text(
title,
style: StyleConfig.fs14cWhitefwNormal,
),
),
Container(
constraints: BoxConstraints(maxWidth: getWidth(context) * 0.5),
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
//decoration: BoxDecorations.customRadius(radius: BorderRadius.only(bottomRight: Radius.circular(8),topRight: Radius.circular(8)),color: ThemeConfig.grey),
child: Text(
value,
style: StyleConfig.fs14cWhitefwNormal,
maxLines: 1,
),
),
const Spacer(),
const Icon(Icons.arrow_drop_down_outlined)
],
));
}
Widget countryDropDown(){
return DropdownButtonFormField<CountryInfo>(
decoration: InputDecoration(
labelText: AppLang.local(context).select_country,
border: OutlineInputBorder(
borderSide: BorderSide(color: ThemeConfig.accentColor)
),
),
value: addressPresenter.selectedCountry,
onChanged: (CountryInfo? country) {
if(country!=null){
addressPresenter.setSelectedCountry(country);
}
},
dropdownColor: Colors.white,
items:addressPresenter.countries.map<DropdownMenuItem<CountryInfo>>((e) =>DropdownMenuItem(
value: e,
child: Text(e.name,style: StyleConfig.fs14fwNormal,),
) ).toList(),
);
}
Widget stateDropDown(){
return DropdownButtonFormField<StateInfo>(
decoration: InputDecoration(
labelText: AppLang.local(context).select_state,
border: OutlineInputBorder(
borderSide: BorderSide(color: ThemeConfig.accentColor)
),
),
value: addressPresenter.selectedState,
onChanged: (StateInfo? state) {
if(state!=null) {
addressPresenter.setSelectedState(state);
}
},
dropdownColor: Colors.white,
items:addressPresenter.states.map<DropdownMenuItem<StateInfo>>((e) =>DropdownMenuItem(
value: e,
child: Text(e.name,style: StyleConfig.fs14fwNormal,),
) ).toList(),
);
}
Widget cityDropDown(){
return DropdownButtonFormField<CityInfo>(
decoration: InputDecoration(
labelText: AppLang.local(context).select_city,
border: OutlineInputBorder(
borderSide: BorderSide(color: ThemeConfig.accentColor)
),
),
value: addressPresenter.selectedCity,
onChanged: (CityInfo? city) {
if(city!=null) {
addressPresenter.setSelectedCity(city);
}
},
dropdownColor: Colors.white,
items:addressPresenter.cities.map<DropdownMenuItem<CityInfo>>((e) =>DropdownMenuItem(
value: e,
child: Text(e.name,style: StyleConfig.fs14fwNormal,),
) ).toList(),
);
}
Widget isDefaultDropDown(){
return DropdownButtonFormField<String>(
decoration: InputDecoration(
labelText: AppLang.local(context).default_address,
border: OutlineInputBorder(
borderSide: BorderSide(color: ThemeConfig.accentColor)
),
),
onChanged: (String? value) {
if(value!=null) {
addressPresenter.setDefaultAddress(value);
}
},
value: addressPresenter.defaultAddress,
dropdownColor: Colors.white,
items:["No", "Set Default"].map<DropdownMenuItem<String>>((e) =>DropdownMenuItem(
value: e,
child: Text(e,style: StyleConfig.fs14fwNormal,),
) ).toList(),
);
}
/*
showCountryDialog() {
showDialog(
context: context,
builder: (context) => ListenableBuilder(
listenable: addressPresenter,
builder: (context, child) {
return AlertDialog(
title: TextField(
onChanged: (text) {
print(text);
addressPresenter.filterCountry(text);
},
decoration: InputDecorations.basic(hint_text: "search...")),
content: Container(
height: 250,
child: SingleChildScrollView(
child: Column(
children: List.generate(
addressPresenter.filteredCountries.length,
(index) => Button(
onPressed: () {
Navigator.pop(context);
},
child: Container(
constraints: BoxConstraints(
minWidth: getWidth(context)),
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 10),
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecorations.basic(),
child: Text(
addressPresenter
.filteredCountries[index].name,
style: StyleConfig.fs14fwNormal,
)),
))),
),
),
actions: [
Button(
color: ThemeConfig.grey,
onPressed: () {
Navigator.pop(context);
},
child: Text(
AppLang.local(context).close,
style: StyleConfig.fs14cWhitefwNormal,
))
],
);
}));
}
showStateDialog() {
showDialog(
context: context,
builder: (context) => ListenableBuilder(
listenable: addressPresenter,
builder: (context, child) {
return AlertDialog(
title: TextField(
onChanged: (text) {
addressPresenter.filterState(text);
},
decoration: InputDecorations.basic(hint_text: "search...")),
content: Container(
height: 250,
child: SingleChildScrollView(
child: Column(
children: List.generate(
addressPresenter.filteredStates.length,
(index) => Button(
onPressed: () {
Navigator.pop(context);
addressPresenter.setSelectedState(
addressPresenter.filteredStates[index]);
},
child: Container(
constraints: BoxConstraints(
minWidth: getWidth(context)),
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 10),
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecorations.basic(),
child: Text(
addressPresenter
.filteredStates[index].name,
style: StyleConfig.fs14fwNormal,
)),
))),
),
),
actions: [
Button(
color: ThemeConfig.grey,
onPressed: () {
Navigator.pop(context);
},
child: Text(
AppLang.local(context).close,
style: StyleConfig.fs14cWhitefwNormal,
))
],
);
}));
}
showCityDialog() {
showDialog(
context: context,
builder: (context) => ListenableBuilder(
listenable: addressPresenter,
builder: (context, child) {
return AlertDialog(
title: TextField(
onChanged: (text) {
addressPresenter.filterCity(text);
},
decoration: InputDecorations.basic(hint_text: "search...")),
content: Container(
height: 250,
child: SingleChildScrollView(
child: Column(
children: List.generate(
addressPresenter.filteredCities.length,
(index) => Button(
onPressed: () {
Navigator.pop(context);
addressPresenter.setSelectedCity(
addressPresenter.filteredCities[index]);
},
child: Container(
constraints: BoxConstraints(
minWidth: getWidth(context)),
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 10),
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecorations.basic(),
child: Text(
addressPresenter
.filteredCities[index].name,
style: StyleConfig.fs14fwNormal,
)),
))),
),
),
actions: [
Button(
color: ThemeConfig.grey,
onPressed: () {
Navigator.pop(context);
},
child: Text(
AppLang.local(context).close,
style: StyleConfig.fs14cWhitefwNormal,
))
],
);
}));
}
*/
}

View File

@@ -0,0 +1,202 @@
import 'package:flutter/material.dart';
import 'package:grostore/app_lang.dart';
import 'package:grostore/configs/style_config.dart';
import 'package:grostore/configs/theme_config.dart';
import 'package:grostore/custom_ui/Boxdecorations.dart';
import 'package:grostore/custom_ui/Button.dart';
import 'package:grostore/custom_ui/common_appbar.dart';
import 'package:grostore/custom_ui/filter_dropdown.dart';
import 'package:grostore/custom_ui/shimmers.dart';
import 'package:grostore/helpers/device_info_helper.dart';
import 'package:grostore/helpers/route.dart';
import 'package:grostore/presenters/address_presenter.dart';
import 'package:grostore/presenters/user_presenter.dart';
import 'package:grostore/screens/address/address_new_or_update.dart';
import 'package:grostore/screens/check_out.dart';
import 'package:provider/provider.dart';
class Addresses extends StatefulWidget {
const Addresses({super.key});
@override
State<Addresses> createState() => _AddressesState();
}
class _AddressesState extends State<Addresses> {
@override
void initState() {
// TODO: implement initState
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Provider.of<AddressPresenter>(context, listen: false).initState();
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CommonAppbar.show(
title: AppLang.local(context).address,
context: context,
bottom: PreferredSize(
preferredSize: Size(getWidth(context), 40),
child: Button(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
minWidth: getWidth(context) - (StyleConfig.padding * 2),
shape: StyleConfig.buttonRadius(2)
.copyWith(side: BorderSide(color: ThemeConfig.extraDarkGrey)),
onPressed: () {
MakeRoute.go(context, AddressNewOrUpdate());
},
child: Text(
AppLang.local(context).add_new_address_ucf,
style: StyleConfig.fs14fwNormal,
),
),
),
),
body: Consumer<AddressPresenter>(builder: (context, data, child) {
return addresses(data);
}),
);
}
Widget addresses(AddressPresenter data) {
return RefreshIndicator(
onRefresh: data.onRefresh,
child: Container(
margin: EdgeInsets.symmetric(horizontal: StyleConfig.padding),
//color: Colors.red,
width: getWidth(context),
child: data.isFetchAddress
? ListView.separated(
itemCount: data.addresses.length,
padding: EdgeInsets.symmetric(
horizontal: StyleConfig.padding, vertical: 10),
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return Material(
clipBehavior: Clip.antiAlias,
borderRadius: const BorderRadius.all(Radius.circular(10)),
child: InkWell(
onTap: (){
MakeRoute.goAndRemoveAll(context,const CheckOut());
},
child: Container(
padding: const EdgeInsets.all(10),
width: getWidth(context),
decoration: BoxDecorations.shadow(radius: 8).copyWith(
border: Border.all(width: 2, color: ThemeConfig.grey)),
child: Stack(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
data.addresses[index].address,
style: StyleConfig.fs14fwNormal,
maxLines: 1,
),
Padding(
padding: const EdgeInsets.only(top: 5.0),
child: Row(
children: [
Text(
"${AppLang.local(context).city}: ",
style: StyleConfig.fs14fwBold,
),
Text(
data.addresses[index].cityName,
style: StyleConfig.fs14fwNormal,
),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 5.0),
child: Row(
children: [
Text(
"${AppLang.local(context).state}: ",
style: StyleConfig.fs14fwBold,
),
Text(
data.addresses[index].stateName,
style: StyleConfig.fs14fwNormal,
),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 5.0),
child: Row(
children: [
Text(
"${AppLang.local(context).country}: ",
style: StyleConfig.fs14fwBold,
),
Text(
data.addresses[index].countryName,
style: StyleConfig.fs14fwNormal,
),
],
),
),
],
),
Positioned(
top: 0,
right: 0,
child: Column(
children: [
SizedBox(
height: 25,
width: 25,
child: Button(
onPressed: (){
MakeRoute.go(context, AddressNewOrUpdate(addressId:data.addresses[index].id ,));
},
padding: EdgeInsets.zero,
minWidth: 10.0,
minHeight: 10.0,
child:const Icon(Icons.edit,),
),
),
const SizedBox(height: 15,),
SizedBox(
height: 25,
width: 25,
child: Button(
onPressed: (){
data.deleteAddress(data.addresses[index].id , context);
},
padding: EdgeInsets.zero,
minWidth: 10.0,
minHeight: 10.0,
child:const Icon(Icons.delete,),
),
),
],
))
],
),
),
),
);
},
separatorBuilder: (context, index) {
return const SizedBox(
height: 10,
);
},
)
: Shimmers.list(10, getWidth(context) * 0.5, 100),
),
);
}
}