rename to one trip
This commit is contained in:
164
one_trip/lib/pages/profile_page/profile_page.dart
Normal file
164
one_trip/lib/pages/profile_page/profile_page.dart
Normal file
@@ -0,0 +1,164 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:one_trip/api/models/homegroup.dart';
|
||||
import 'package:one_trip/widgets/text_entry_dialog.dart';
|
||||
import 'package:one_trip/pages/profile_page/widgets/homegroup_card_widget.dart';
|
||||
import 'package:one_trip/pages/profile_page/widgets/profile_card_widget.dart';
|
||||
import 'package:one_trip/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.getMe();
|
||||
|
||||
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.patchMe(homegroup: id);
|
||||
|
||||
if (response != null) {
|
||||
setState(() {
|
||||
_userInfo = response;
|
||||
});
|
||||
}
|
||||
},
|
||||
onCreate: () async {
|
||||
String? name = await textEntryDialog(
|
||||
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.create(name);
|
||||
if (hg == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
User? response =
|
||||
await _userInfo.patchMe(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:one_trip/api/models/homegroup.dart';
|
||||
import 'package:one_trip/api/models/homegroupinvite.dart';
|
||||
import 'package:one_trip/api/models/simpleuser.dart';
|
||||
import 'package:one_trip/pages/profile_page/widgets/invite_homegroup_dialog.dart';
|
||||
import 'package:one_trip/pages/profile_page/widgets/user_chip.dart';
|
||||
import 'package:one_trip/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.get(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.get(widget.homegroupID);
|
||||
if (hg == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_homegroup = hg;
|
||||
_groupUsers = [];
|
||||
_groupInvites = [];
|
||||
_groupInviteUsers = {};
|
||||
|
||||
for (int id in hg.users) {
|
||||
SimpleUser? u = await SimpleUser.get(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.get(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].delete();
|
||||
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.create(_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:one_trip/api/models/simpleuser.dart';
|
||||
import 'package:one_trip/pages/profile_page/widgets/user_chip.dart';
|
||||
import 'package:one_trip/theme.dart';
|
||||
import 'package:one_trip/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:one_trip/api/models/user.dart';
|
||||
import 'package:flutter_svg_provider/flutter_svg_provider.dart';
|
||||
import 'package:one_trip/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
one_trip/lib/pages/profile_page/widgets/user_chip.dart
Normal file
51
one_trip/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:one_trip/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),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
132
one_trip/lib/pages/recipes_page/recipes_page.dart
Normal file
132
one_trip/lib/pages/recipes_page/recipes_page.dart
Normal file
@@ -0,0 +1,132 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:one_trip/api/models/homegroup.dart';
|
||||
import 'package:one_trip/api/models/recipe.dart';
|
||||
import 'package:one_trip/api/models/user.dart';
|
||||
import 'package:one_trip/pages/recipes_page/widgets/recipe_card_widget.dart';
|
||||
import 'package:one_trip/widgets/text_entry_dialog.dart';
|
||||
|
||||
class RecipesPage extends StatefulWidget {
|
||||
const RecipesPage({super.key});
|
||||
|
||||
@override
|
||||
State<RecipesPage> createState() => _RecipesPageState();
|
||||
}
|
||||
|
||||
class _RecipesPageState extends State<RecipesPage> {
|
||||
late Future<List<Recipe>> _recipes;
|
||||
late User _userInfo;
|
||||
|
||||
Future<List<Recipe>> _fetchList() async {
|
||||
User? userInfo = await User.getMe();
|
||||
if (userInfo == null || userInfo.homegroup == null) {
|
||||
return [];
|
||||
}
|
||||
_userInfo = userInfo;
|
||||
|
||||
List<Recipe> recipes = await Recipe.getList(_userInfo.homegroup!);
|
||||
return recipes;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_recipes = _fetchList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: _recipes,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
} else if (snapshot.hasData &&
|
||||
snapshot.connectionState == ConnectionState.done) {
|
||||
return RecipeList(
|
||||
recipes: snapshot.data!, homegroup: _userInfo.homegroup!);
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RecipeList extends StatefulWidget {
|
||||
final List<Recipe> recipes;
|
||||
final int homegroup;
|
||||
const RecipeList({super.key, required this.recipes, required this.homegroup});
|
||||
|
||||
@override
|
||||
State<RecipeList> createState() => _RecipeListState();
|
||||
}
|
||||
|
||||
class _RecipeListState extends State<RecipeList> {
|
||||
int? _expandedCard;
|
||||
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
children: [
|
||||
ListView.separated(
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: widget.recipes.length,
|
||||
separatorBuilder: (context, index) => const SizedBox(height: 12),
|
||||
itemBuilder: (context, index) => RecipeCard(
|
||||
recipe: widget.recipes[index],
|
||||
isExpanded: _expandedCard == index,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
if (_expandedCard == index) {
|
||||
_expandedCard = null;
|
||||
} else {
|
||||
_expandedCard = index;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: FloatingActionButton.extended(
|
||||
onPressed: () async {
|
||||
String? name =
|
||||
await textEntryDialog(context, "Recipe Name", "Recipe");
|
||||
|
||||
if (name == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (name == "") {
|
||||
showError("Recipe name cannot be empty");
|
||||
return;
|
||||
}
|
||||
|
||||
Recipe? created = await Recipe.create(name, widget.homegroup);
|
||||
},
|
||||
label: Row(
|
||||
children: const [Icon(Icons.note_add), Text("New Recipe")],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
133
one_trip/lib/pages/recipes_page/widgets/recipe_card_widget.dart
Normal file
133
one_trip/lib/pages/recipes_page/widgets/recipe_card_widget.dart
Normal file
@@ -0,0 +1,133 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:one_trip/api/models/ingredient.dart';
|
||||
import 'package:one_trip/api/models/recipe.dart';
|
||||
import 'package:one_trip/theme.dart';
|
||||
import 'package:one_trip/widgets/text_entry_dialog.dart';
|
||||
|
||||
class RecipeCard extends StatelessWidget {
|
||||
final Recipe recipe;
|
||||
final bool isExpanded;
|
||||
final Function() onTap;
|
||||
const RecipeCard({
|
||||
super.key,
|
||||
required this.recipe,
|
||||
required this.isExpanded,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 10,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: const Radius.circular(10),
|
||||
bottom: isExpanded ? Radius.zero : const Radius.circular(10)),
|
||||
),
|
||||
margin: EdgeInsets.zero,
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
recipe.name,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
),
|
||||
AnimatedRotation(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
turns: isExpanded ? 0.5 : 0,
|
||||
child: const Icon(Icons.expand_more, size: 30),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
AnimatedSize(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: isExpanded
|
||||
? IngredientSection(ingredients: recipe.ingredients)
|
||||
: const SizedBox(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
AnimatedSize(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: isExpanded
|
||||
? ElevatedButton(
|
||||
style: bottomButtonStyle,
|
||||
onPressed: () async {
|
||||
String? name = await textEntryDialog(
|
||||
context, "Ingredient Name", "Ingredient");
|
||||
},
|
||||
child: const Text("Add Ingredient"),
|
||||
)
|
||||
: const SizedBox(),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class IngredientSection extends StatelessWidget {
|
||||
final List<Ingredient> ingredients;
|
||||
const IngredientSection({super.key, required this.ingredients});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TextStyle ingredientStyle = Theme.of(context)
|
||||
.textTheme
|
||||
.bodyLarge!
|
||||
.copyWith(color: Theme.of(context).colorScheme.onSurface);
|
||||
|
||||
return Container(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: (ingredients.length / 2).ceil(),
|
||||
shrinkWrap: true,
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
color: index % 2 == 0
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
if (ingredients.length % 2 == 0 ||
|
||||
index * 2 <= ingredients.length - 2) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
ingredients[index * 2].name,
|
||||
style: ingredientStyle,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(ingredients[index * 2 + 1].name,
|
||||
style: ingredientStyle),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Row(
|
||||
children: [
|
||||
Text(ingredients[index * 2].name, style: ingredientStyle),
|
||||
],
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
125
one_trip/lib/pages/themetest.dart
Normal file
125
one_trip/lib/pages/themetest.dart
Normal file
@@ -0,0 +1,125 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ColorPage extends StatelessWidget {
|
||||
const ColorPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GridView.count(
|
||||
crossAxisCount: 3,
|
||||
children: [
|
||||
// FIRST ROW
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Primary",
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.onPrimary),
|
||||
)),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Secondary",
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.onSecondary),
|
||||
)),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.tertiary,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Tertiary",
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.onTertiary),
|
||||
)),
|
||||
),
|
||||
|
||||
// SECOND ROW
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Primary Container",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer),
|
||||
)),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.secondaryContainer,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Secondary Container",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSecondaryContainer),
|
||||
)),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.tertiaryContainer,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Tertiary Container",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onTertiaryContainer),
|
||||
)),
|
||||
),
|
||||
|
||||
// THIRD ROW
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Error",
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.onError),
|
||||
)),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Background",
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.onBackground),
|
||||
)),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Surface",
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.onSurface),
|
||||
)),
|
||||
),
|
||||
|
||||
// FOURTH ROW
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.errorContainer,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Error Container",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onErrorContainer),
|
||||
)),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: Theme.of(context).colorScheme.surfaceVariant,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Surface Variant",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user