import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:qr_flutter/qr_flutter.dart'; import '/utils/storage/database.dart'; import '/models/my_profile.dart'; import '/components/custom_circle_avatar.dart'; class Profile extends StatefulWidget { final MyProfile profile; const Profile({ Key? key, required this.profile, }) : super(key: key); @override State createState() => _ProfileState(); } class _ProfileState extends State { Widget usernameHeading() { return Row( children: [ const CustomCircleAvatar( icon: Icon(Icons.person, size: 40), imagePath: null, // TODO: Add image here radius: 30, ), const SizedBox(width: 20), Text( widget.profile.username, style: const TextStyle( fontSize: 25, fontWeight: FontWeight.w500, ), ), // widget.conversation.admin ? IconButton( // iconSize: 20, // icon: const Icon(Icons.edit), // padding: const EdgeInsets.all(5.0), // splashRadius: 25, // onPressed: () { // // TODO: Redirect to edit screen // }, // ) : const SizedBox.shrink(), ], ); } Widget _profileQrCode() { return Container( child: QrImage( data: 'This is a simple QR code', version: QrVersions.auto, size: 130, gapless: true, ), width: 130, height: 130, color: Theme.of(context).colorScheme.onPrimary, ); } Widget settings() { return Align( alignment: Alignment.centerLeft, child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const SizedBox(height: 5), TextButton.icon( label: const Text( 'Disappearing Messages', style: TextStyle(fontSize: 16) ), icon: const Icon(Icons.timer), style: ButtonStyle( alignment: Alignment.centerLeft, foregroundColor: MaterialStateProperty.resolveWith( (Set states) { return Theme.of(context).colorScheme.onBackground; }, ) ), onPressed: () { print('Disappearing Messages'); } ), ], ), ); } Widget logout() { bool isTesting = dotenv.env["ENVIRONMENT"] == 'development'; return Align( alignment: Alignment.centerLeft, child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ TextButton.icon( label: const Text( 'Logout', style: TextStyle(fontSize: 16) ), icon: const Icon(Icons.exit_to_app), style: const ButtonStyle( alignment: Alignment.centerLeft, ), onPressed: () { deleteDb(); MyProfile.logout(); Navigator.pushNamedAndRemoveUntil(context, '/landing', ModalRoute.withName('/landing')); } ), isTesting ? TextButton.icon( label: const Text( 'Delete Database', style: TextStyle(fontSize: 16) ), icon: const Icon(Icons.delete_forever), style: const ButtonStyle( alignment: Alignment.centerLeft, ), onPressed: () { deleteDb(); } ) : const SizedBox.shrink(), ], ), ); } @override Widget build(BuildContext context) { return Scaffold( body: SingleChildScrollView( physics: const BouncingScrollPhysics(), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ SafeArea( child: Padding( padding: const EdgeInsets.only(left: 16,right: 16,top: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: const [ Text( 'Profile', style: TextStyle( fontSize: 32, fontWeight: FontWeight.bold, ), ), ], ), ), ), Padding( padding: const EdgeInsets.only(top: 16,left: 16,right: 16), child: Column( children: [ const SizedBox(height: 30), usernameHeading(), const SizedBox(height: 30), _profileQrCode(), const SizedBox(height: 30), settings(), const SizedBox(height: 30), logout(), ], ) ), ], ), ), ); } }