feat: changing language done

This commit is contained in:
jahongireshonqulov
2025-10-25 20:13:11 +05:00
parent 2750564b08
commit 651a7e5e9d
31 changed files with 621 additions and 57 deletions

View File

@@ -0,0 +1,21 @@
import '../../../../core/theme/app_icons.dart';
mixin AccountMixins {
final List<String> leadingIcons = [
AppIcons.icOrdersSvg,
AppIcons.icLike,
AppIcons.icRewards,
AppIcons.icWallet,
AppIcons.icGift,
AppIcons.icHelp,
AppIcons.icPromotions,
AppIcons.icUberPass,
AppIcons.icDeliver,
AppIcons.icLanguage,
AppIcons.icSettings,
];
final List<String> flags = [AppIcons.icEn, AppIcons.icUz, AppIcons.icRu];
final List<String> languages = ["English", "O'zbekcha", "Русский"];
}

View File

@@ -1,3 +1,5 @@
import 'package:food_delivery_client/feature/account/presentation/pages/account_page/widgets/w_account_body.dart';
import '../../../../../food_delivery_client.dart';
class AccountPage extends StatelessWidget {
@@ -5,38 +7,7 @@ class AccountPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder<LanguageBloc, LanguageState>(
builder: (context, state) {
return WLayout(
child: Scaffold(
body: Center(
child: Column(
children: [
Text(context.loc.iCantSignIn),
TextButton(
onPressed: () {
if (state.currentLocale == Locale("uz")) {
context.read<LanguageBloc>().add(
LanguageEvent.changed(Locale('ru')),
);
} else if (state.currentLocale == Locale("ru")) {
context.read<LanguageBloc>().add(
LanguageEvent.changed(Locale('en')),
);
} else {
context.read<LanguageBloc>().add(
LanguageEvent.changed(Locale('uz')),
);
}
},
child: Text("changelang"),
),
],
),
),
),
);
},
);
return WAccountBody();
}
}

View File

@@ -0,0 +1,208 @@
import 'package:flutter/cupertino.dart';
import 'package:food_delivery_client/feature/account/presentation/mixins/account_mixins.dart';
import '../../../../../../food_delivery_client.dart';
class WAccountBody extends StatelessWidget with AccountMixins {
WAccountBody({super.key});
@override
Widget build(BuildContext context) {
final List<String> titles = [
context.loc.orders,
context.loc.yourFavourites,
context.loc.restaurantRewards,
context.loc.wallet,
context.loc.sendAGift,
context.loc.help,
context.loc.promotions,
context.loc.uberPass,
context.loc.deliverWithUber,
context.loc.changeLanguage,
context.loc.settings,
];
return WLayout(
child: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(56),
child: WAccountAppBar().paddingSymmetric(horizontal: 19),
),
body: LayoutBuilder(
builder: (context, constraints) => ConstrainedBox(
constraints: BoxConstraints(minHeight: constraints.maxHeight),
child: ListView.builder(
shrinkWrap: true,
itemCount: leadingIcons.length,
padding: EdgeInsets.symmetric(vertical: 15),
physics: const AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
itemBuilder: (context, index) => WAccountRowItem(
onTap: () {
if (index == 9) {
WChangeLanguage().show(context);
}
},
svgPath: leadingIcons[index],
title: titles[index],
),
),
),
),
),
);
}
}
class WAccountAppBar extends StatelessWidget {
const WAccountAppBar({super.key});
@override
Widget build(BuildContext context) {
return AppBar(
centerTitle: false,
leading: ClipRRect(
borderRadius: AppUtils.kBorderRadius40,
child: SizedBox(
child: Image.asset(
AppImages.imgAvatar,
height: 36,
width: 36,
fit: BoxFit.cover,
),
),
),
title: Text('Felix', style: AppTextStyles.size18Medium),
);
}
}
class WAccountRowItem extends StatelessWidget {
const WAccountRowItem({
super.key,
required this.svgPath,
required this.title,
this.subTitle,
this.leadingIcon,
required this.onTap,
});
final String svgPath;
final String title;
final String? subTitle;
final Widget? leadingIcon;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: Ink(
child: Row(
spacing: 24,
mainAxisAlignment: MainAxisAlignment.start,
children: [
leadingIcon ??
SizedBox(
height: 24,
width: 24,
child: SvgPicture.asset(svgPath),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: AppTextStyles.size14Medium),
if (subTitle != null)
Text(
subTitle!,
style: AppTextStyles.size14Medium.copyWith(
color: AppColors.c34A853,
),
),
],
),
],
).paddingSymmetric(vertical: 16, horizontal: 22),
),
);
}
}
class WChangeLanguage extends StatelessWidget with AccountMixins {
WChangeLanguage({super.key});
show(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (context) => Wrap(children: [this]),
);
}
@override
Widget build(BuildContext context) {
return BlocBuilder<LanguageBloc, LanguageState>(
builder: (context, state) {
return Material(
color: AppColors.cFFFFFF,
borderRadius: AppUtils.kBorderRadiusTop20,
child: SizedBox(
width: context.w,
child: SafeArea(
child: Column(
children: [
10.verticalSpace,
SizedBox(
height: 6,
width: 100,
child: DecoratedBox(
decoration: BoxDecoration(
color: AppColors.cEEEEEE,
borderRadius: AppUtils.kBorderRadius8,
),
),
),
10.verticalSpace,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
context.loc.changeLanguage,
style: AppTextStyles.size24Medium,
),
IconButton(
onPressed: () {
context.pop();
},
icon: SvgPicture.asset(AppIcons.icClose),
),
],
).paddingSymmetric(horizontal: 16),
15.verticalSpace,
Column(
children: List.generate(3, (index) {
return AppListTile(
onPressed: () {
context.read<LanguageBloc>().add(
LanguageEvent.changed(L10n.locales[index]),
);
},
isSelected: L10n.locales[index] == state.currentLocale,
svgPath: '',
leading: SizedBox(
height: 24,
width: 24,
child: Image.asset(flags[index]),
),
title: languages[index],
titleTextStyle: AppTextStyles.size16Medium,
);
}),
),
],
),
),
),
);
},
);
}
}