Account Management mostly implemented
This commit is contained in:
165
grocery_helper/lib/pages/profile_page/profile_page.dart
Normal file
165
grocery_helper/lib/pages/profile_page/profile_page.dart
Normal file
@@ -0,0 +1,165 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:grocery_helper/api/models/homegroup.dart';
|
||||
import 'package:grocery_helper/widgets/text_entry_dialog.dart';
|
||||
import 'package:grocery_helper/pages/profile_page/widgets/homegroup_card_widget.dart';
|
||||
import 'package:grocery_helper/pages/profile_page/widgets/profile_card_widget.dart';
|
||||
import 'package:grocery_helper/api/models/user.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'dart:io' show Platform, File;
|
||||
|
||||
class ProfilePage extends StatefulWidget {
|
||||
const ProfilePage({super.key});
|
||||
|
||||
@override
|
||||
State<ProfilePage> createState() => _ProfilePageState();
|
||||
}
|
||||
|
||||
class _ProfilePageState extends State<ProfilePage> {
|
||||
late User _userInfo;
|
||||
late Future<bool> _isLoaded;
|
||||
|
||||
Future<bool> _loadProfile() async {
|
||||
User? userInfo = await User.fetchUser();
|
||||
|
||||
if (userInfo != null) {
|
||||
_userInfo = userInfo;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void showError(String text) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
content: Text(text),
|
||||
action: SnackBarAction(
|
||||
textColor: Theme.of(context).colorScheme.onError,
|
||||
label: "Dismiss",
|
||||
onPressed: () => ScaffoldMessenger.of(context).hideCurrentSnackBar(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_isLoaded = _loadProfile();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: _isLoaded,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
} else if (snapshot.hasData &&
|
||||
snapshot.connectionState == ConnectionState.done) {
|
||||
return Scrollbar(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
ProfileCard(
|
||||
userInfo: _userInfo,
|
||||
onTapPhoto: () async {
|
||||
if (Platform.isAndroid) {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final XFile? photo = await picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
imageQuality: 70,
|
||||
maxWidth: 400,
|
||||
maxHeight: 400);
|
||||
|
||||
if (photo == null) {
|
||||
return;
|
||||
}
|
||||
File file = File(photo.path);
|
||||
|
||||
User? response = await _userInfo.uploadImage(file);
|
||||
if (response != null) {
|
||||
setState(() {
|
||||
_userInfo = response;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
showError(
|
||||
"This feature is only available on Android");
|
||||
}
|
||||
},
|
||||
onLogout: () async {
|
||||
const storage = FlutterSecureStorage();
|
||||
await storage.delete(key: "token");
|
||||
|
||||
if (mounted) {
|
||||
Navigator.pushReplacementNamed(context, "/login");
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_userInfo.homegroup == null
|
||||
? CreateJoinHomegroup(
|
||||
invites: _userInfo.homegroupInvites,
|
||||
onJoin: (id) async {
|
||||
User? response =
|
||||
await _userInfo.patch(homegroup: id);
|
||||
|
||||
if (response != null) {
|
||||
setState(() {
|
||||
_userInfo = response;
|
||||
});
|
||||
}
|
||||
},
|
||||
onCreate: () async {
|
||||
String? name = await createHomegroupDialog(
|
||||
context,
|
||||
"Create Homegroup",
|
||||
"Homegroup Name",
|
||||
defaultValue: "${_userInfo.username}'s Kitchen",
|
||||
);
|
||||
if (name == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (name == "") {
|
||||
showError("Homegroup name must not be empty");
|
||||
return;
|
||||
}
|
||||
|
||||
Homegroup? hg =
|
||||
await Homegroup.createHomegroup(name);
|
||||
if (hg == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
User? response =
|
||||
await _userInfo.patch(homegroup: hg.id);
|
||||
|
||||
if (response != null) {
|
||||
setState(() {
|
||||
_userInfo = response;
|
||||
});
|
||||
}
|
||||
},
|
||||
)
|
||||
: EditHomegroup(
|
||||
homegroupID: _userInfo.homegroup!,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grocery_helper/api/models/homegroup.dart';
|
||||
import 'package:grocery_helper/api/models/homegroupinvite.dart';
|
||||
import 'package:grocery_helper/api/models/simpleuser.dart';
|
||||
import 'package:grocery_helper/pages/profile_page/widgets/invite_homegroup_dialog.dart';
|
||||
import 'package:grocery_helper/pages/profile_page/widgets/user_chip.dart';
|
||||
import 'package:grocery_helper/theme.dart';
|
||||
|
||||
class CreateJoinHomegroup extends StatefulWidget {
|
||||
final List<int> invites;
|
||||
final Function(int id) onJoin;
|
||||
final Function() onCreate;
|
||||
|
||||
const CreateJoinHomegroup({
|
||||
super.key,
|
||||
required this.invites,
|
||||
required this.onJoin,
|
||||
required this.onCreate,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CreateJoinHomegroup> createState() => _CreateJoinHomegroupState();
|
||||
}
|
||||
|
||||
class _CreateJoinHomegroupState extends State<CreateJoinHomegroup> {
|
||||
late Future<bool> _isLoaded;
|
||||
final List<Homegroup> _invitedGroups = [];
|
||||
|
||||
Future<bool> _loadInvites() async {
|
||||
for (int id in widget.invites) {
|
||||
Homegroup? hg = await Homegroup.fetchHomegroup(id);
|
||||
|
||||
if (hg != null) {
|
||||
_invitedGroups.add(hg);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_isLoaded = _loadInvites();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 10,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(10), bottom: Radius.zero),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Create or Join a Homegroup",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const Divider(),
|
||||
widget.invites.isEmpty
|
||||
? const Text(
|
||||
"You have not been invited to join any homegroups")
|
||||
: Center(
|
||||
child: FutureBuilder(
|
||||
future: _isLoaded,
|
||||
builder: ((context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
} else if (snapshot.hasData &&
|
||||
snapshot.connectionState ==
|
||||
ConnectionState.done) {
|
||||
return ListView.separated(
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (context, index) {
|
||||
return JoinRow(
|
||||
hg: _invitedGroups[index],
|
||||
onJoin: (id) => widget.onJoin(id),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) =>
|
||||
const Divider(),
|
||||
itemCount: _invitedGroups.length);
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
style: bottomButtonStyle,
|
||||
onPressed: () => widget.onCreate(),
|
||||
child: const Text("Create Homegroup"),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class JoinRow extends StatelessWidget {
|
||||
final Homegroup hg;
|
||||
final Function(int id) onJoin;
|
||||
const JoinRow({super.key, required this.hg, required this.onJoin});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(hg.name),
|
||||
ElevatedButton(
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStatePropertyAll(
|
||||
Theme.of(context).colorScheme.secondary),
|
||||
foregroundColor: MaterialStatePropertyAll(
|
||||
Theme.of(context).colorScheme.onSecondary)),
|
||||
onPressed: () => onJoin(hg.id),
|
||||
child: Row(
|
||||
children: const [
|
||||
Text("Join"),
|
||||
SizedBox(width: 4),
|
||||
Icon(Icons.check)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EditHomegroup extends StatefulWidget {
|
||||
final int homegroupID;
|
||||
|
||||
const EditHomegroup({super.key, required this.homegroupID});
|
||||
|
||||
@override
|
||||
State<EditHomegroup> createState() => _EditHomegroupState();
|
||||
}
|
||||
|
||||
class _EditHomegroupState extends State<EditHomegroup> {
|
||||
late Future<bool> _isLoaded;
|
||||
Homegroup? _homegroup;
|
||||
List<SimpleUser> _groupUsers = [];
|
||||
List<HomegroupInvite> _groupInvites = [];
|
||||
Map<HomegroupInvite, SimpleUser> _groupInviteUsers = {};
|
||||
|
||||
Future<bool> _loadHomegroup() async {
|
||||
Homegroup? hg = await Homegroup.fetchHomegroup(widget.homegroupID);
|
||||
if (hg == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_homegroup = hg;
|
||||
_groupUsers = [];
|
||||
_groupInvites = [];
|
||||
_groupInviteUsers = {};
|
||||
|
||||
for (int id in hg.users) {
|
||||
SimpleUser? u = await SimpleUser.fetchUser(id: id);
|
||||
|
||||
if (u != null) {
|
||||
_groupUsers.add(u);
|
||||
}
|
||||
}
|
||||
|
||||
for (int id in hg.inviteIDs) {
|
||||
HomegroupInvite? invite = await HomegroupInvite.get(id);
|
||||
if (invite == null || hg.users.contains(invite.userID)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SimpleUser? u = await SimpleUser.fetchUser(id: invite.userID);
|
||||
|
||||
if (u != null) {
|
||||
_groupInvites.add(invite);
|
||||
_groupInviteUsers[invite] = u;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_isLoaded = _loadHomegroup();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TextStyle textstylebase = Theme.of(context).textTheme.titleSmall!;
|
||||
|
||||
final TextStyle textstyle = TextStyle(
|
||||
fontSize: textstylebase.fontSize,
|
||||
fontWeight: textstylebase.fontWeight,
|
||||
color: textstylebase.color,
|
||||
decorationColor: textstylebase.color,
|
||||
decorationStyle: TextDecorationStyle.solid,
|
||||
decoration: TextDecoration.underline);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 10,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(10), bottom: Radius.zero),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: FutureBuilder(
|
||||
future: _isLoaded,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(child: Text(snapshot.error.toString()));
|
||||
} else if (snapshot.hasData &&
|
||||
snapshot.connectionState == ConnectionState.done) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_homegroup!.name,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
const Divider(),
|
||||
Text(
|
||||
"Users",
|
||||
style: textstyle,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ListView.separated(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: _groupUsers.length,
|
||||
separatorBuilder: (context, index) => const Divider(),
|
||||
itemBuilder: (context, index) {
|
||||
return UserRow(
|
||||
user: _groupUsers[index],
|
||||
onButton: (id) {},
|
||||
buttonText: "Kick",
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(),
|
||||
Text(
|
||||
"Pending Invites",
|
||||
style: textstyle,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_groupInvites.isEmpty
|
||||
? const Text("None")
|
||||
: ListView.separated(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (context, index) {
|
||||
return UserRow(
|
||||
user:
|
||||
_groupInviteUsers[_groupInvites[index]]!,
|
||||
onButton: (id) async {
|
||||
bool success = await _groupInvites[index]
|
||||
.deleteInvite();
|
||||
if (success) {
|
||||
setState(() {
|
||||
_isLoaded = _loadHomegroup();
|
||||
});
|
||||
}
|
||||
},
|
||||
buttonText: "Cancel",
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) =>
|
||||
const Divider(),
|
||||
itemCount: _groupInvites.length)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
style: bottomButtonStyle,
|
||||
onPressed: () async {
|
||||
List<int>? selectedIDs = await inviteHomegroupDialog(context);
|
||||
|
||||
if (selectedIDs == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int id in selectedIDs) {
|
||||
await HomegroupInvite.createInvite(_homegroup!.id, id);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isLoaded = _loadHomegroup();
|
||||
});
|
||||
},
|
||||
child: const Text("Invite"),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class UserRow extends StatelessWidget {
|
||||
final SimpleUser user;
|
||||
final Function(int id) onButton;
|
||||
final String buttonText;
|
||||
const UserRow(
|
||||
{super.key,
|
||||
required this.user,
|
||||
required this.onButton,
|
||||
required this.buttonText});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ButtonStyle buttonStyle = ButtonStyle(
|
||||
padding: const MaterialStatePropertyAll(
|
||||
EdgeInsets.symmetric(vertical: 8, horizontal: 4)),
|
||||
backgroundColor:
|
||||
MaterialStatePropertyAll(Theme.of(context).colorScheme.secondary),
|
||||
foregroundColor: MaterialStatePropertyAll(
|
||||
Theme.of(context).colorScheme.onSecondary));
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SmallUserChip(user: user),
|
||||
ElevatedButton(
|
||||
style: buttonStyle,
|
||||
onPressed: () => onButton(user.id),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(buttonText),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(Icons.close)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grocery_helper/api/models/simpleuser.dart';
|
||||
import 'package:grocery_helper/pages/profile_page/widgets/user_chip.dart';
|
||||
import 'package:grocery_helper/theme.dart';
|
||||
import 'package:grocery_helper/widgets/pagination_listview.dart';
|
||||
|
||||
class InviteHomegroupDialog extends StatefulWidget {
|
||||
const InviteHomegroupDialog({super.key});
|
||||
|
||||
@override
|
||||
State<InviteHomegroupDialog> createState() => _InviteHomegroupDialogState();
|
||||
}
|
||||
|
||||
class _InviteHomegroupDialogState extends State<InviteHomegroupDialog> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
ListViewState _listState = ListViewState.inactive;
|
||||
List<int> selectedIDs = [];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
margin: EdgeInsets.zero,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Invite to Homegroup",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const Divider(),
|
||||
TextFormField(
|
||||
controller: _searchController,
|
||||
textInputAction: TextInputAction.search,
|
||||
onFieldSubmitted: (value) {
|
||||
setState(() {
|
||||
_listState = ListViewState.changed;
|
||||
});
|
||||
},
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_listState = ListViewState.inactive;
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
label: const Text("Search"),
|
||||
isDense: true,
|
||||
suffix: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_listState = ListViewState.changed;
|
||||
});
|
||||
|
||||
// https://flutterigniter.com/dismiss-keyboard-form-lose-focus/
|
||||
FocusScopeNode currentFocus = FocusScope.of(context);
|
||||
if (!currentFocus.hasPrimaryFocus) {
|
||||
currentFocus.unfocus();
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.search),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
LayoutBuilder(
|
||||
builder: (builder, constraints) {
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints.expand(
|
||||
width: constraints.maxWidth - 8,
|
||||
height: 160,
|
||||
),
|
||||
child: PaginationListView(
|
||||
state: _listState,
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (context, data) {
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
// _ready = false;
|
||||
_listState = ListViewState.inUse;
|
||||
if (selectedIDs.contains(data.id)) {
|
||||
selectedIDs.remove(data.id);
|
||||
} else {
|
||||
selectedIDs.add(data.id);
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
color: selectedIDs.contains(data.id)
|
||||
? Theme.of(context).colorScheme.secondary
|
||||
: null,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
SmallUserChip(
|
||||
user: data,
|
||||
radius: 20,
|
||||
textColor: selectedIDs.contains(data.id)
|
||||
? Theme.of(context).colorScheme.onSecondary
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
seperatorBuilder: (context, data) {
|
||||
return const Divider();
|
||||
},
|
||||
dataProvider: (int page) async {
|
||||
SearchResult result =
|
||||
await SimpleUser.search(_searchController.text, page);
|
||||
List<dynamic> users = List<dynamic>.from(result.users);
|
||||
|
||||
if (result.next == null) {
|
||||
users.add(null);
|
||||
}
|
||||
|
||||
return users;
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text("Cancel"),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context, selectedIDs),
|
||||
child: const Text("Done")),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<int>?> inviteHomegroupDialog(BuildContext context) async {
|
||||
List<int>? selectedIDs = await showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return Dialog(
|
||||
child: ScrollConfiguration(
|
||||
behavior: MyBehavior(), child: const InviteHomegroupDialog()),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
return selectedIDs;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grocery_helper/api/models/user.dart';
|
||||
import 'package:flutter_svg_provider/flutter_svg_provider.dart';
|
||||
import 'package:grocery_helper/theme.dart';
|
||||
|
||||
class ProfileCard extends StatelessWidget {
|
||||
final User userInfo;
|
||||
final Function() onTapPhoto;
|
||||
final Function() onLogout;
|
||||
const ProfileCard(
|
||||
{super.key,
|
||||
required this.userInfo,
|
||||
required this.onTapPhoto,
|
||||
required this.onLogout});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 10,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(10), bottom: Radius.zero),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
radius: 42,
|
||||
child: CircleAvatar(
|
||||
radius: 40,
|
||||
backgroundImage: userInfo.imageUrl != null
|
||||
? NetworkImage(userInfo.imageUrl!)
|
||||
: Image(
|
||||
image: Svg('assets/images/person.svg',
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimaryContainer),
|
||||
).image,
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.primaryContainer,
|
||||
// https://github.com/flutter/flutter/issues/42901#issuecomment-708050484
|
||||
child: Material(
|
||||
shape: const CircleBorder(),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => onTapPhoto(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"${userInfo.firstName} ${userInfo.lastName}",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
Text("@${userInfo.username}",
|
||||
style: Theme.of(context).textTheme.titleLarge),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
style: bottomButtonStyle,
|
||||
onPressed: () => onLogout(),
|
||||
child: const Text("Log out"),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
51
grocery_helper/lib/pages/profile_page/widgets/user_chip.dart
Normal file
51
grocery_helper/lib/pages/profile_page/widgets/user_chip.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg_provider/flutter_svg_provider.dart';
|
||||
import 'package:grocery_helper/api/models/simpleuser.dart';
|
||||
|
||||
class SmallUserChip extends StatelessWidget {
|
||||
final SimpleUser user;
|
||||
final double? radius;
|
||||
final Color? textColor;
|
||||
const SmallUserChip(
|
||||
{super.key, required this.user, this.radius, this.textColor});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
double baseRadius = radius ?? 30;
|
||||
return Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: baseRadius,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
child: CircleAvatar(
|
||||
radius: baseRadius - 2,
|
||||
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
||||
backgroundImage: user.imageUrl != null
|
||||
? NetworkImage(user.imageUrl!)
|
||||
: Image(
|
||||
image: Svg('assets/images/person.svg',
|
||||
color:
|
||||
Theme.of(context).colorScheme.onPrimaryContainer),
|
||||
).image,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"${user.firstName} ${user.lastName}",
|
||||
style: TextStyle(
|
||||
color: textColor ?? Theme.of(context).colorScheme.onSurface),
|
||||
),
|
||||
Text(
|
||||
"@${user.username}",
|
||||
style: TextStyle(
|
||||
color: textColor ?? Theme.of(context).colorScheme.onSurface),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user