// ignore_for_file: prefer_const_constructors import 'package:firebase_auth/firebase_auth.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; import 'package:flutter_application_1/Project/ProfilePage/EditProfilePage/edit_profile_page.dart'; import 'package:flutter_application_1/Project/ProfilePage/widgets/contact.dart'; import 'package:flutter_application_1/Project/utils/colors.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import '../main.dart'; // ignore: use_key_in_widget_constructors class ProfileProject extends StatelessWidget { final User? user = FirebaseAuth.instance.currentUser; @override Widget build(BuildContext context) { return Scaffold( body: StreamBuilder( stream: FirebaseFirestore.instance .collection('users') .doc(user?.uid) .snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) { return Center(child: CircularProgressIndicator()); } var data = snapshot.data!.data() as Map; var firstName = data['firstName']; var lastName = data['lastName']; var email = data['email']; var school = data['school']; var studentID = data['studentID']; return Container( decoration: BoxDecoration( // Replace with your desired green color image: DecorationImage( image: NetworkImage( 'https://firebasestorage.googleapis.com/v0/b/project-tongz-1.appspot.com/o/admin_images%2F43cff4203e1f0266746c576111253e94.jpg?alt=media&token=4f8258bc-d0e8-4d90-a002-7362b168abfc', ), fit: BoxFit.cover, ), ), child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( child: Padding( padding: const EdgeInsets.symmetric( horizontal: 10.0, ), child: ListView( scrollDirection: Axis.vertical, children: [ Column( children: [ SizedBox( height: 5, ), Row( children: [ Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(13), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.2), blurRadius: 8, offset: Offset(0, 3), ), ], border: Border.all( color: Colors.black, width: 2), ), child: Text( 'My Profile', style: Theme.of(context) .textTheme .headlineMedium! .copyWith( fontWeight: FontWeight.bold, color: Colors.black87, ), ), ), Spacer(), Container( alignment: Alignment.centerRight, child: InkWell( onTap: () { Navigator.push( context, MaterialPageRoute( builder: ((context) => EditProfilePage()), ), ); }, child: Container( width: 30, height: 30, decoration: BoxDecoration( shape: BoxShape.circle, color: Colors.white, ), child: Icon( Icons.settings, color: Colors.black, ), ), ), ), ], ), SizedBox( height: 10, ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 130, height: 130, decoration: BoxDecoration( shape: BoxShape.circle, color: kGreenColor, border: Border.all( color: Colors.black, width: 2, ), ), child: CircleAvatar( backgroundImage: NetworkImage(data['image_url']), radius: 70, ), ), ], ), SizedBox( height: 15, ), Container( width: 400, height: 97, decoration: BoxDecoration( color: kGreyLightColor, border: Border.all( width: 2, color: Colors.black, ), borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.2), spreadRadius: 5, blurRadius: 2, offset: Offset(0, 3), ), ], ), child: Padding( padding: const EdgeInsets.all(5.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Name: ${firstName.length + lastName.length > 30 ? '${firstName.substring(0, 15)} ${lastName.substring(0, 3)}...' : '$firstName $lastName'}', style: TextStyle( fontSize: 20, color: Colors.black, fontWeight: FontWeight.w700, ), overflow: TextOverflow.ellipsis, ), SizedBox( height: 5, ), Text( 'Email : $email', style: TextStyle( fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, ), ), SizedBox( height: 5, ), Text( '$school', style: TextStyle( fontSize: 12, color: Colors.black, fontWeight: FontWeight.w400, ), ), SizedBox( height: 5, ), Text( 'StudentID : $studentID', style: TextStyle( fontSize: 12, color: Colors.black, fontWeight: FontWeight.w400, ), ), ], ), ), ), Divider(), ProfileMenuWidget( title: 'Contact us for help', icon: Icons.connect_without_contact_sharp, iconColor: Colors.black, onPress: () { Navigator.push( context, MaterialPageRoute( builder: ((context) => ContactPro()), ), ); }, endIcon: true), SizedBox( height: 5, ), ProfileMenuWidget( title: 'Logout', textColor: Colors.red, iconColor: Colors.red, icon: FontAwesomeIcons.signOut, onPress: () async { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text( "Logout", style: Theme.of(context) .textTheme .headlineSmall! .copyWith( fontWeight: FontWeight.bold, ), ), content: Text( 'Are you sure you want to logout?'), actions: [ TextButton( onPressed: () { Navigator.of(context).pop(); }, child: const Text( 'Cancel', style: TextStyle(color: Colors.blue), ), ), TextButton( onPressed: () async { await FirebaseAuth.instance .signOut(); // ignore: use_build_context_synchronously Navigator.pushAndRemoveUntil( context, MaterialPageRoute( builder: (context) => Splash()), (Route route) => false, ); }, child: const Text( 'Logout', style: TextStyle( color: Colors.red, ), ), ), ], ); }, ); }, endIcon: false, ), ], ) ], ), ), ), ], ), ); }, ), ); } Widget buildEditIcon(Color color) => buildCircle( all: 8, child: Icon( Icons.edit, color: color, size: 20, )); // Builds/Makes Circle for Edit Icon on Profile Picture Widget buildCircle({ required Widget child, required double all, }) => ClipOval( child: Container( padding: EdgeInsets.all(all), color: Colors.white, child: child, )); } class ProfileMenuWidget extends StatelessWidget { const ProfileMenuWidget({ Key? key, required this.title, required this.icon, required this.onPress, this.endIcon = true, this.textColor, this.iconColor, }) : super(key: key); final String title; final IconData icon; final VoidCallback onPress; final bool endIcon; final Color? textColor; final Color? iconColor; @override Widget build(BuildContext context) { return Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(30), color: Colors.white, border: Border.all( width: 2, color: Colors.black, ), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.5), spreadRadius: 2, blurRadius: 5, offset: Offset(0, 3), ), ], ), child: ListTile( onTap: onPress, leading: Icon( icon, size: 35, color: iconColor, ), title: Text( title, style: TextStyle( fontSize: 20, color: textColor, fontWeight: FontWeight.w700, ), ), trailing: endIcon ? Container( width: 30, height: 30, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), color: kGreyLightColor, ), child: Icon( FontAwesomeIcons.angleRight, color: Colors.black, ), ) : null), ); } }