-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch User Filter to users collection
- Loading branch information
Showing
5 changed files
with
43 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 14 additions & 44 deletions
58
lib/pages/home_page/inventory_view/filters/user_filter.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,35 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:spare_parts/dtos/user_dto.dart'; | ||
import 'package:spare_parts/services/callable_service.dart'; | ||
import 'package:spare_parts/entities/custom_user.dart'; | ||
import 'package:spare_parts/widgets/dialogs/user_selection_dialog.dart'; | ||
import 'package:spare_parts/widgets/inputs/multiselect_button.dart'; | ||
import 'package:spare_parts/widgets/user_avatar.dart'; | ||
|
||
class UserFilter extends StatefulWidget { | ||
final List<String> selectedUsers; | ||
final void Function(List<String>) onChanged; | ||
final IconData? icon; | ||
final List<CustomUser> selectedUsers; | ||
final void Function(List<CustomUser>) onChanged; | ||
|
||
const UserFilter({ | ||
super.key, | ||
required this.selectedUsers, | ||
required this.onChanged, | ||
this.icon, | ||
}); | ||
|
||
@override | ||
State<UserFilter> createState() => _UserFilterState(); | ||
} | ||
|
||
class _UserFilterState extends State<UserFilter> { | ||
late Future<List<UserDto>> _userQuery; | ||
|
||
@override | ||
void initState() { | ||
final callableService = context.read<CallableService>(); | ||
_userQuery = callableService.getUsers(); | ||
|
||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return FutureBuilder<List<UserDto>>( | ||
future: _userQuery, | ||
builder: (context, snap) { | ||
if (!snap.hasData || snap.hasError) { | ||
return SizedBox.square( | ||
dimension: 20, | ||
child: CircularProgressIndicator(strokeWidth: 3), | ||
); | ||
} | ||
|
||
final users = snap.data!; | ||
|
||
return MultiselectButton( | ||
buttonLabel: 'Borrowers', | ||
values: users.map((u) => u.id).toList(), | ||
selectedValues: widget.selectedUsers, | ||
onConfirm: widget.onChanged, | ||
icon: widget.icon, | ||
labelBuilder: (uid) => | ||
users.singleWhere((user) => user.id == uid).name, | ||
leadingBuilder: (uid) { | ||
final user = users.singleWhere((user) => user.id == uid); | ||
return UserAvatar(photoUrl: user.photoUrl); | ||
}, | ||
); | ||
}, | ||
return MultiselectButton<CustomUser>( | ||
buttonLabel: 'Borrowers', | ||
values: [], | ||
selectedValues: [], | ||
onConfirm: widget.onChanged, | ||
icon: Icons.filter_list, | ||
dialog: UserSelectionDialog( | ||
selectedUsers: widget.selectedUsers, | ||
title: 'Pick Borrowers', | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters