303 lines
11 KiB
Dart
303 lines
11 KiB
Dart
// ignore_for_file: use_build_context_synchronously
|
|
|
|
import 'package:adaptix/adaptix.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:sapaly_shop/features/screens/auth/login/login_screen.dart';
|
|
import 'package:sapaly_shop/features/screens/category/category_screen.dart';
|
|
import 'package:sapaly_shop/features/screens/drawer/contacts.dart';
|
|
import 'package:sapaly_shop/features/screens/drawer/new_arrival.dart';
|
|
import 'package:sapaly_shop/features/screens/drawer/sales.dart';
|
|
import 'package:sapaly_shop/features/screens/drawer/shops.dart';
|
|
import 'package:sapaly_shop/features/screens/home/home_screen.dart';
|
|
import 'package:sapaly_shop/features/screens/settings/settings_screen.dart';
|
|
import 'package:sapaly_shop/features/services/page_navigator.dart';
|
|
import 'package:sapaly_shop/features/services/requests.dart';
|
|
import 'package:sapaly_shop/features/widgets/sapaly_icon.dart';
|
|
import 'package:sapaly_shop/models/category_model.dart';
|
|
import 'package:sapaly_shop/models/settings_model.dart';
|
|
import 'package:sapaly_shop/providers/user_provider.dart';
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
|
|
|
import '../../../constants/global_variables.dart';
|
|
import '../../../constants/modals.dart';
|
|
import '../../../themes/app_theme.dart';
|
|
import 'about_us.dart';
|
|
|
|
class SapalyDrawer extends StatefulWidget {
|
|
SapalyDrawer({super.key});
|
|
|
|
@override
|
|
State<SapalyDrawer> createState() => _SapalyDrawerState();
|
|
}
|
|
|
|
class _SapalyDrawerState extends State<SapalyDrawer> {
|
|
List<String> icons = [
|
|
'assets/icons/drawerIcons/home.svg',
|
|
'assets/icons/drawerIcons/category.svg',
|
|
'assets/icons/drawerIcons/info.svg',
|
|
'assets/icons/drawerIcons/sale.svg',
|
|
'assets/icons/drawerIcons/car.svg',
|
|
'assets/icons/drawerIcons/shops.svg',
|
|
'assets/icons/drawerIcons/mail.svg',
|
|
// 'assets/icons/drawerIcons/settings.svg',
|
|
];
|
|
|
|
List<String> iconNames = [
|
|
'home',
|
|
'categories',
|
|
'about_us',
|
|
'sales',
|
|
'new_arrival',
|
|
'shops',
|
|
'contacts',
|
|
// 'settings'
|
|
];
|
|
|
|
List<Widget> routes = [
|
|
const HomeScreen(),
|
|
const CategoryScreen(),
|
|
const AboutUsScreen(),
|
|
const SalesScreen(),
|
|
const NewArrivalScreen(),
|
|
const ShopsScreen(),
|
|
const ContactsScreen(),
|
|
// const SettingsScreen(),
|
|
];
|
|
|
|
List<CategoryModel> categories = [];
|
|
|
|
Future<List<CategoryModel>> getCategories() async {
|
|
final data = await API().getCategories();
|
|
if (mounted) {
|
|
setState(() {
|
|
categories = data;
|
|
});
|
|
}
|
|
return categories;
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
if (categories == null) getCategories();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var settings = Provider.of<SettingsModel>(context, listen: false);
|
|
var me = Provider.of<UserProvider>(context, listen: false);
|
|
return Drawer(
|
|
backgroundColor: AppTheme.whiteColor,
|
|
child: Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 15.adaptedPx()),
|
|
child: Column(
|
|
children: [
|
|
DrawerHeader(
|
|
padding: EdgeInsets.zero,
|
|
child: Row(
|
|
children: [
|
|
Image.asset(
|
|
'assets/images/sapalyLogo.png',
|
|
width: 60.adaptedPx(),
|
|
height: 60.adaptedPx(),
|
|
),
|
|
SizedBox(width: 10.adaptedPx()),
|
|
Text(
|
|
GlobalVariables.kAppName,
|
|
style: GoogleFonts.poppins(
|
|
textStyle: Theme.of(context)
|
|
.primaryTextTheme
|
|
.bodyMedium!
|
|
.copyWith(
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 18.adaptedPx(),
|
|
color: AppTheme.blackColor,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
me.user.user.email == '' && me.user.user.name == ''
|
|
? Container()
|
|
: GestureDetector(
|
|
onTap: () {
|
|
PageNavigator(ctx: context)
|
|
.nextPage(page: const SettingsScreen());
|
|
},
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.account_circle,
|
|
size: 35.adaptedPx(),
|
|
color: AppTheme.lightPrimaryColor,
|
|
),
|
|
SizedBox(width: 10.adaptedPx()),
|
|
Expanded(
|
|
child: Text(
|
|
me.user.user.email.isEmpty
|
|
? me.user.user.email
|
|
: me.user.user.name,
|
|
softWrap: true,
|
|
maxLines: 4,
|
|
style: Theme.of(context)
|
|
.primaryTextTheme
|
|
.bodyMedium
|
|
?.copyWith(
|
|
fontWeight: FontWeight.w600,
|
|
color: AppTheme.blackColor,
|
|
fontSize: 13.adaptedPx(),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(
|
|
vertical: 15.adaptedPx(),
|
|
horizontal: 5.adaptedPx(),
|
|
),
|
|
child: GestureDetector(
|
|
onTap: () async {
|
|
var lang =
|
|
await languagePicker(context, settings.currentLanguage);
|
|
|
|
if (lang != null) {
|
|
await settings.setLanguage(lang);
|
|
Navigator.of(context, rootNavigator: true)
|
|
.pushNamedAndRemoveUntil('/home', (route) => false);
|
|
}
|
|
},
|
|
child: Row(
|
|
children: [
|
|
SapalyIcon(
|
|
onTap: () async {
|
|
var lang = await languagePicker(
|
|
context, settings.currentLanguage);
|
|
|
|
if (lang != null) {
|
|
await settings.setLanguage(lang);
|
|
Navigator.of(context, rootNavigator: true)
|
|
.pushNamedAndRemoveUntil(
|
|
'/home', (route) => false);
|
|
}
|
|
},
|
|
width: 25.adaptedPx(),
|
|
height: 25.adaptedPx(),
|
|
hasBadge: false,
|
|
child: SvgPicture.asset('assets/icons/lang.svg'),
|
|
),
|
|
SizedBox(width: 10.adaptedPx()),
|
|
Text(
|
|
'currentLang'.translation,
|
|
style: Theme.of(context)
|
|
.primaryTextTheme
|
|
.bodyMedium
|
|
?.copyWith(
|
|
color: AppTheme.blackColor,
|
|
fontSize: 15.adaptedPx(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
ListView.builder(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
itemCount: icons.length,
|
|
scrollDirection: Axis.vertical,
|
|
itemBuilder: (context, index) {
|
|
return TextButton(
|
|
style: TextButton.styleFrom(
|
|
padding: EdgeInsets.symmetric(
|
|
vertical: GlobalVariables.verticalPadding(context) / 3,
|
|
horizontal:
|
|
GlobalVariables.horizontalPadding(context) / 2,
|
|
),
|
|
),
|
|
onPressed: () {
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (context) => routes[index]));
|
|
},
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
SvgPicture.asset(
|
|
icons[index],
|
|
color: AppTheme.lightPrimaryColor,
|
|
width: 22.adaptedPx(),
|
|
height: 22.adaptedPx(),
|
|
),
|
|
SizedBox(width: 10.adaptedPx()),
|
|
Text(
|
|
iconNames[index].translation,
|
|
style: Theme.of(context)
|
|
.primaryTextTheme
|
|
.bodyMedium
|
|
?.copyWith(
|
|
fontWeight: FontWeight.w500,
|
|
color: AppTheme.blackColor,
|
|
fontSize: 14.adaptedPx(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
const Spacer(),
|
|
TextButton(
|
|
onPressed: () {
|
|
launchUrlString('tel://+99363508564');
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.call_outlined),
|
|
SizedBox(width: 15.adaptedPx()),
|
|
Text(
|
|
'+993 63 508564',
|
|
style:
|
|
Theme.of(context).primaryTextTheme.bodyMedium?.copyWith(
|
|
fontWeight: FontWeight.w500,
|
|
color: AppTheme.blackColor,
|
|
fontSize: 15.adaptedPx(),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
TextButton(
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.call_outlined),
|
|
SizedBox(width: 15.adaptedPx()),
|
|
Text(
|
|
'+993 12 973168',
|
|
style:
|
|
Theme.of(context).primaryTextTheme.bodyMedium?.copyWith(
|
|
fontWeight: FontWeight.w500,
|
|
color: AppTheme.blackColor,
|
|
fontSize: 15.adaptedPx(),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
onPressed: () {
|
|
launchUrlString('tel://+99312973168');
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
SizedBox(height: 20.adaptedPx()),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|