sapaly_store/lib/features/screens/drawer/sapaly_drawer.dart

261 lines
9.0 KiB
Dart
Raw Normal View History

2023-03-10 21:53:18 +00:00
// ignore_for_file: use_build_context_synchronously
2023-02-25 15:18:33 +00:00
import 'package:adaptix/adaptix.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_fonts/google_fonts.dart';
2023-03-10 21:53:18 +00:00
import 'package:provider/provider.dart';
2023-03-09 08:29:03 +00:00
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';
2023-03-09 08:29:03 +00:00
import 'package:sapaly_shop/features/screens/home/home_screen.dart';
import 'package:sapaly_shop/features/screens/settings/settings_screen.dart';
2023-03-10 21:53:18 +00:00
import 'package:sapaly_shop/features/services/requests.dart';
2023-03-09 08:29:03 +00:00
import 'package:sapaly_shop/features/widgets/sapaly_icon.dart';
2023-03-10 21:53:18 +00:00
import 'package:sapaly_shop/models/category_model.dart';
import 'package:sapaly_shop/models/settings_model.dart';
2023-02-25 15:18:33 +00:00
import 'package:url_launcher/url_launcher_string.dart';
import '../../../constants/global_variables.dart';
2023-03-10 21:53:18 +00:00
import '../../../constants/modals.dart';
import '../../../themes/app_theme.dart';
2023-03-02 03:04:51 +00:00
import 'about_us.dart';
2023-02-25 15:18:33 +00:00
2023-03-10 21:53:18 +00:00
class SapalyDrawer extends StatefulWidget {
2023-02-25 15:18:33 +00:00
SapalyDrawer({super.key});
2023-03-10 21:53:18 +00:00
@override
State<SapalyDrawer> createState() => _SapalyDrawerState();
}
class _SapalyDrawerState extends State<SapalyDrawer> {
2023-02-25 15:18:33 +00:00
List<String> icons = [
2023-03-09 08:29:03 +00:00
'assets/icons/drawerIcons/home.svg',
2023-02-25 15:18:33 +00:00
'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',
2023-03-09 08:29:03 +00:00
'assets/icons/drawerIcons/settings.svg',
2023-02-25 15:18:33 +00:00
];
List<String> iconNames = [
2023-03-09 08:29:03 +00:00
'Home',
2023-02-25 15:18:33 +00:00
'Categories',
'About us',
'Sales',
'New arrival',
'Shops',
'Contacts',
2023-03-10 21:53:18 +00:00
'settings'
2023-02-25 15:18:33 +00:00
];
List<Widget> routes = [
2023-03-09 08:29:03 +00:00
const HomeScreen(),
2023-02-25 15:18:33 +00:00
const CategoryScreen(),
2023-03-02 03:04:51 +00:00
const AboutUsScreen(),
const SalesScreen(),
const NewArrivalScreen(),
const ShopsScreen(),
const ContactsScreen(),
2023-03-09 08:29:03 +00:00
const SettingsScreen(),
2023-02-25 15:18:33 +00:00
];
2023-03-10 21:53:18 +00:00
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();
}
2023-02-25 15:18:33 +00:00
@override
Widget build(BuildContext context) {
2023-03-10 21:53:18 +00:00
SettingsModel settings = Provider.of<SettingsModel>(context, listen: true);
2023-02-25 15:18:33 +00:00
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,
2023-02-25 15:18:33 +00:00
style: GoogleFonts.poppins(
textStyle: Theme.of(context)
.primaryTextTheme
.bodyMedium!
.copyWith(
fontWeight: FontWeight.w600,
fontSize: 18.adaptedPx(),
color: AppTheme.blackColor,
),
),
),
],
),
),
2023-03-10 21:53:18 +00:00
Row(
children: [
Icon(
Icons.account_circle,
size: 35.adaptedPx(),
color: AppTheme.lightPrimaryColor,
),
SizedBox(width: 10.adaptedPx()),
Text(
'Aman Amanow',
softWrap: true,
maxLines: 2,
style:
Theme.of(context).primaryTextTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: AppTheme.blackColor,
fontSize: 13.adaptedPx(),
),
),
const Spacer(),
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: 22.adaptedPx(),
height: 22.adaptedPx(),
hasBadge: false,
child: SvgPicture.asset('assets/icons/lang.svg'),
),
Text(
'En',
style:
Theme.of(context).primaryTextTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
color: AppTheme.blackColor,
fontSize: 13.adaptedPx(),
),
),
],
2023-02-25 15:18:33 +00:00
),
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) / 2,
horizontal:
GlobalVariables.horizontalPadding(context) / 2,
2023-02-25 15:18:33 +00:00
),
),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => routes[index]));
},
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SvgPicture.asset(
icons[index],
color: AppTheme.lightPrimaryColor,
2023-03-10 21:53:18 +00:00
width: 22.adaptedPx(),
height: 22.adaptedPx(),
2023-02-25 15:18:33 +00:00
),
SizedBox(width: 10.adaptedPx()),
Text(
2023-03-10 21:53:18 +00:00
iconNames[index].translation,
2023-02-25 15:18:33 +00:00
style: Theme.of(context)
.primaryTextTheme
.bodyMedium
?.copyWith(
fontWeight: FontWeight.w500,
color: AppTheme.blackColor,
2023-03-10 21:53:18 +00:00
fontSize: 14.adaptedPx(),
2023-02-25 15:18:33 +00:00
),
),
],
),
);
},
),
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,
2023-03-10 21:53:18 +00:00
fontSize: 15.adaptedPx(),
2023-02-25 15:18:33 +00:00
),
)
],
),
),
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,
2023-03-10 21:53:18 +00:00
fontSize: 15.adaptedPx(),
2023-02-25 15:18:33 +00:00
),
)
],
),
onPressed: () {
launchUrlString('tel://+99312973168');
Navigator.of(context).pop();
},
),
SizedBox(height: 20.adaptedPx()),
],
),
),
);
}
}