Compare commits
2 Commits
e14984d4a9
...
bce4cdcb2d
| Author | SHA1 | Date | |
|---|---|---|---|
| bce4cdcb2d | |||
| fa0e9a5dfd |
@@ -37,6 +37,10 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
db = Provider.of<AppDatabase>(context, listen: false);
|
db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
|
loadPlayerList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadPlayerList() {
|
||||||
_allPlayersFuture = db.playerDao.getAllPlayers();
|
_allPlayersFuture = db.playerDao.getAllPlayers();
|
||||||
_allPlayersFuture.then((loadedPlayers) {
|
_allPlayersFuture.then((loadedPlayers) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -99,6 +103,41 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
minHeight: 45,
|
minHeight: 45,
|
||||||
),
|
),
|
||||||
hintText: 'Search for players',
|
hintText: 'Search for players',
|
||||||
|
trailingButtonShown: true,
|
||||||
|
trailingButtonEnabled:
|
||||||
|
_searchBarController.text.isNotEmpty,
|
||||||
|
onTrailingButtonPressed: () async {
|
||||||
|
String playerName = _searchBarController.text;
|
||||||
|
if (playerName.isEmpty) return;
|
||||||
|
bool success = await db.playerDao.addPlayer(
|
||||||
|
player: Player(name: playerName),
|
||||||
|
);
|
||||||
|
if (success) {
|
||||||
|
loadPlayerList();
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
backgroundColor: CustomTheme.boxColor,
|
||||||
|
content: Center(
|
||||||
|
child: Text(
|
||||||
|
'Successfully added player $playerName.',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
_searchBarController.clear();
|
||||||
|
} else {
|
||||||
|
SnackBar(
|
||||||
|
backgroundColor: CustomTheme.boxColor,
|
||||||
|
content: Center(
|
||||||
|
child: Text(
|
||||||
|
'Could not add player $playerName.',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (value.isEmpty) {
|
if (value.isEmpty) {
|
||||||
|
|||||||
@@ -6,11 +6,17 @@ class CustomSearchBar extends StatelessWidget {
|
|||||||
final String hintText;
|
final String hintText;
|
||||||
final ValueChanged<String>? onChanged;
|
final ValueChanged<String>? onChanged;
|
||||||
final BoxConstraints? constraints;
|
final BoxConstraints? constraints;
|
||||||
|
final bool trailingButtonEnabled;
|
||||||
|
final bool trailingButtonShown;
|
||||||
|
final VoidCallback? onTrailingButtonPressed;
|
||||||
|
|
||||||
const CustomSearchBar({
|
const CustomSearchBar({
|
||||||
super.key,
|
super.key,
|
||||||
required this.controller,
|
required this.controller,
|
||||||
required this.hintText,
|
required this.hintText,
|
||||||
|
this.trailingButtonShown = false,
|
||||||
|
this.trailingButtonEnabled = true,
|
||||||
|
this.onTrailingButtonPressed,
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.constraints,
|
this.constraints,
|
||||||
});
|
});
|
||||||
@@ -25,6 +31,20 @@ class CustomSearchBar extends StatelessWidget {
|
|||||||
onChanged: onChanged,
|
onChanged: onChanged,
|
||||||
hintStyle: WidgetStateProperty.all(const TextStyle(fontSize: 16)),
|
hintStyle: WidgetStateProperty.all(const TextStyle(fontSize: 16)),
|
||||||
leading: const Icon(Icons.search),
|
leading: const Icon(Icons.search),
|
||||||
|
trailing: trailingButtonShown
|
||||||
|
? [
|
||||||
|
GestureDetector(
|
||||||
|
onTap: onTrailingButtonPressed,
|
||||||
|
child: Icon(
|
||||||
|
Icons.add_circle,
|
||||||
|
color: trailingButtonEnabled
|
||||||
|
? null
|
||||||
|
: Colors.grey.withValues(alpha: 0.2),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 5),
|
||||||
|
]
|
||||||
|
: null,
|
||||||
backgroundColor: WidgetStateProperty.all(CustomTheme.boxColor),
|
backgroundColor: WidgetStateProperty.all(CustomTheme.boxColor),
|
||||||
side: WidgetStateProperty.all(BorderSide(color: CustomTheme.boxBorder)),
|
side: WidgetStateProperty.all(BorderSide(color: CustomTheme.boxBorder)),
|
||||||
shape: WidgetStateProperty.all(
|
shape: WidgetStateProperty.all(
|
||||||
|
|||||||
Reference in New Issue
Block a user