Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
13 kB
1
Indexable
Never
// ignore_for_file: prefer_const_constructors

import 'dart:convert';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:druto_shopping/apps/drawerScreen/repository/drawer_repository.dart';
import 'package:druto_shopping/apps/drawerScreen/widgets/drawer_shimmer_screen.dart';
import 'package:druto_shopping/apps/drawerScreen/widgets/icon_box.dart';
import 'package:druto_shopping/general/constants/urls.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get_storage/get_storage.dart';
import 'package:dio/dio.dart' as dio;
import 'package:image_picker/image_picker.dart';
import '../../../general/theme/theme_provider.dart';
import '../../checkoutScreen/widgets/custom_textstyle.dart';
import '../model/profile_model.dart';

class DrawerScreen extends ConsumerStatefulWidget {
  const DrawerScreen({Key? key}) : super(key: key);

  @override
  ConsumerState<DrawerScreen> createState() => _DrawerScreenState();
}

class _DrawerScreenState extends ConsumerState<DrawerScreen> {
  final storage = GetStorage();
  late Future<ProfileModel> data;
  File? file;

  @override
  Widget build(BuildContext context) {
    var w = MediaQuery.of(context).size.width;
    final profiledata = ref.watch(profileData);
    final appThemeState = ref.watch(appThemeStateNotifier);
    return SafeArea(
      child: profiledata.when(
        data: ((data) => Drawer(
              backgroundColor: Color(0xffFEB716),
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    Padding(
                      padding: const EdgeInsets.only(right: 10, top: 10),
                      child: Container(
                        height: 40,
                        alignment: Alignment.centerRight,
                        child: InkWell(
                            onTap: () {
                              Navigator.pop(context);
                            },
                            child: Icon(
                              Icons.close,
                            )),
                      ),
                    ),
                    SizedBox(
                      height: 140,
                      width: w,
                      child: Column(
                        children: [
                          Stack(
                            children: [
                              storage.read('image') != null
                                  ? Container(
                                      height: 100,
                                      width: 100,
                                      decoration:
                                          BoxDecoration(shape: BoxShape.circle),
                                      child: Image.file(
                                        storage.read('image'),
                                        fit: BoxFit.contain,
                                      ),
                                    )
                                  : Image.asset(
                                      "assets/images/users.png",
                                      height: 100,
                                      width: 100,
                                    ),
                              Positioned(
                                top: 80,
                                left: 70,
                                child: GestureDetector(
                                    onTap: () {
                                      _getImageCamera();
                                      print('camera open');
                                    },
                                    child: Icon(Icons.camera_alt_outlined)),
                              )
                            ],
                          ),
                          Text(
                            data.data.name,
                            style: CustomTextStyle(25, context, Colors.black),
                          )
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 25,
                    ),
                    SizedBox(
                      height: 40,
                      child: InkWell(
                        onTap: () {
                          //Navigator.pushNamed(context, EditProfile.route);
                        },
                        child: ListTile(
                          onTap: () {
                            Navigator.popAndPushNamed(context, "/profile");
                          },
                          leading: CustomIconBox(FontAwesomeIcons.circleUser),
                          title: const Text(
                            "Profile",
                            style: TextStyle(
                                fontSize: 20, fontWeight: FontWeight.w500),
                          ),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: ListTile(
                        leading: CustomIconBox(Icons.category),
                        title: Text(
                          "Category",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.w500),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: ListTile(
                        onTap: () {
                          Navigator.pushNamed(context, "/favoritepage");
                        },
                        leading: CustomIconBox(Icons.favorite_outline),
                        title: Text(
                          "Favorite",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.w500),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: ListTile(
                        leading: CustomIconBox(Icons.view_list_outlined),
                        title: Text(
                          "View & looks",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.w500),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: InkWell(
                        onTap: () {
                          Navigator.pushNamed(context, "/voucher");
                        },
                        child: ListTile(
                          leading: CustomIconBox(Icons.discount_outlined),
                          title: Text(
                            "Vouchers",
                            style: TextStyle(
                                fontSize: 20, fontWeight: FontWeight.w500),
                          ),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: ListTile(
                        onTap: () {
                          Navigator.popAndPushNamed(context, '/contactpage');
                        },
                        leading: CustomIconBox(FontAwesomeIcons.locationDot),
                        title: Text(
                          "Address",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.w500),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: ListTile(
                        leading: CustomIconBox(Icons.dark_mode),
                        title: Text(
                          "Dark Mode",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.w500),
                        ),
                        trailing: Switch(
                          value: appThemeState.isDarkModeEnabled ? false : true,
                          onChanged: (bool value) {
                            appThemeState.setDarkModeState();
                            storage.write(
                                'darkMode', appThemeState.isDarkModeEnabled);
                            Navigator.pop(context);
                          },
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 40,
                    ),
                    Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 20),
                      child: Divider(
                        thickness: 0.8,
                        color: Colors.black,
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: ListTile(
                        onTap: () {
                          Navigator.pushNamed(context, "/settingpage");
                        },
                        leading: Icon(
                          Icons.settings,
                          color: Colors.black,
                        ),
                        title: Text(
                          "Settings",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.w500),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: ListTile(
                        leading: Icon(
                          Icons.help_outline_rounded,
                          color: Colors.black,
                        ),
                        title: Text(
                          "Help Center",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.w500),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: ListTile(
                        onTap: () {
                          Navigator.pushNamed(context, "/termspage");
                        },
                        leading: Icon(
                          Icons.save_outlined,
                          color: Colors.black,
                        ),
                        title: Text(
                          "Terms & Conditions",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.w500),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: ListTile(
                        onTap: () {
                          storage.remove('token');
                          if (storage.read('token') == null) {
                            Navigator.pushNamed(context, "/signIn");
                          }
                        },
                        leading: const Icon(
                          Icons.logout_rounded,
                          color: Colors.black,
                        ),
                        title: Text(
                          "Log out",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.w500),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            )),
        error: (e, s) => Text('error occured'),
        loading: (() => DrawerScreenShimmer()),
      ),
    );
  }

  Future _getImageCamera() async {
    try {
      final image = await ImagePicker().pickImage(source: ImageSource.camera);
      if (image == null) return;

      final tempimage = File(image.path);
      setState(() {
        this.file = tempimage;
      });

      storage.write('image', tempimage);
    } on Exception catch (e) {
      print('Image Cant Pick Because of: ==> $e');
    }
  }
}