mirrored_repositories/SwasthyaSetu/lib



import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:swasthya_setu/providers/details.dart';

import 'package:swasthya_setu/user_pages/user_home_page.dart';
import 'package:swasthya_setu/user_pages/user_profile.dart';
import 'package:swasthya_setu/utils/colours.dart';
import 'package:swasthya_setu/utils/drawer_item.dart';


import '../pages/historyappointments.dart';
import '../user_pages/user_report_page.dart';


class Sidebar extends StatefulWidget {
  final Size size;
  final String userid;

  const Sidebar({Key? key, required this.size,required this.userid}) : super(key: key);

  @override
  // ignore: library_private_types_in_public_api
  _SidebarState createState() => _SidebarState();
}

class _SidebarState extends State<Sidebar> {
  @override
  void initState() {
    super.initState();
    context.read<UserDetailsProvider>().getUserdetails();
  }

  @override
  Widget build(BuildContext context) {
    Map<String, dynamic> userDetailsMap =
        Provider.of<UserDetailsProvider>(context, listen: true)
            .getUserDetailsMap;

    return Drawer(
      child: Material(
        color: mainwhite,
        child: Padding(
          padding: const EdgeInsets.fromLTRB(15.0, 30, 24, 0),
          child: Column(
            children: [
              headerWidget(userDetailsMap,widget.size),
              const SizedBox(height: 10),
              const Divider(thickness: 1, height: 2, color: Colors.green),
              const SizedBox(height: 20),
              DrawerItem(
                name: 'Dashboard',
                icon: Icons.dashboard_outlined,
                onPressed: () => onItemPressed(context, index: 0),
              ),
              const SizedBox(height: 30),
              DrawerItem(
                name: 'Reports',
                icon: Icons.receipt,
                onPressed: () => onItemPressed(context, index: 1),
              ),
              const SizedBox(height: 30),
              DrawerItem(
                name: 'Appointments',
                icon: Icons.calendar_month,
                onPressed: () => onItemPressed(context, index: 2),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget headerWidget(Map<String, dynamic> userDetailsMap,Size size) {
    return GestureDetector(onTap: () {
            Navigator.of(context).push(MaterialPageRoute(
              builder: ((context) => UserProfilePage(
                size: widget.size,
                name: userDetailsMap['name'],
                number: userDetailsMap['number'],
                age: userDetailsMap['age'],
                image: userDetailsMap['photoURL'],
                gender: userDetailsMap['gender'],
                mail: userDetailsMap['email'],
                address: userDetailsMap['address'],
              )),
            ));
          },
      child: Column(
        children: [
          CircleAvatar(
              backgroundImage: NetworkImage("${userDetailsMap['photoURL']}"),
              radius: size.width*0.2,
            ),
          
          const SizedBox(width: 30),
          Text(
            "${userDetailsMap['name']}",
            style: const TextStyle(color: Colors.black, fontSize: 30,fontWeight: FontWeight.w600),
          ),
        ],
      ),
    );
  }

  void onItemPressed(BuildContext context, {required int index}) {
    Navigator.pop(context);

    switch (index) {
      case 0:
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => UserHomePage(size: widget.size)));
        break;
      case 1:
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => const UserReportPage()));
        break;
      case 2:
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => AppointmentHistory(userUid: widget.userid,)));
        break;
      default:
        Navigator.pop(context);
        break;
    }
  }
}

