-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2039cfd
commit 7d2f978
Showing
5 changed files
with
168 additions
and
165 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
Future<dynamic> confirmBox({ | ||
required BuildContext context, | ||
required String title, | ||
required String content, | ||
required Function()? onValidate, | ||
}) { | ||
return showDialog( | ||
context: context, | ||
builder: (context) => AlertDialog( | ||
title: Text(title), | ||
content: Text(content), | ||
actions: [ | ||
TextButton( | ||
onPressed: onValidate, | ||
child: const Text("Yes"), | ||
), | ||
TextButton( | ||
onPressed: () => Navigator.of(context).pop(), | ||
child: const Text("No"), | ||
), | ||
], | ||
), | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
class HeaderTile extends StatelessWidget { | ||
const HeaderTile(this.text, {super.key}); | ||
|
||
final String text; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ListTile( | ||
title: Text( | ||
text, | ||
style: const TextStyle( | ||
fontFeatures: [FontFeature.enable('smcp')], | ||
), | ||
), | ||
tileColor: Theme.of(context).splashColor, | ||
dense: false, | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
import '../../model/participant.dart'; | ||
import '../../model/project.dart'; | ||
import '../dialogs/confirm_box.dart'; | ||
|
||
class ParticipantTile extends StatefulWidget { | ||
ParticipantTile({ | ||
super.key, | ||
required this.project, | ||
required this.participant, | ||
required this.onChange, | ||
required this.setHasNew, | ||
}); | ||
|
||
final Project project; | ||
Participant? participant; | ||
final Function() onChange; | ||
final void Function(bool v) setHasNew; | ||
|
||
@override | ||
State<ParticipantTile> createState() => _ParticipantTileState(); | ||
} | ||
|
||
class _ParticipantTileState extends State<ParticipantTile> { | ||
late TextEditingController controller; | ||
|
||
bool edit = false; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
bool hasParticipant = widget.participant != null; | ||
if (!hasParticipant) edit = true; | ||
|
||
bool isMe = widget.participant == widget.project.currentParticipant; | ||
|
||
controller = TextEditingController( | ||
text: hasParticipant | ||
? widget.participant!.pseudo + (isMe && !edit ? ' (me)' : '') | ||
: '', | ||
); | ||
|
||
return ListTile( | ||
onTap: () { | ||
widget.project.currentParticipant = widget.participant; | ||
widget.onChange(); | ||
}, | ||
title: TextField( | ||
autofocus: true, | ||
enabled: edit, | ||
maxLines: 1, | ||
maxLength: 30, | ||
maxLengthEnforcement: MaxLengthEnforcement.enforced, | ||
decoration: InputDecoration( | ||
counterText: "", | ||
border: edit ? null : InputBorder.none, | ||
), | ||
controller: controller, | ||
style: TextStyle( | ||
fontWeight: isMe ? FontWeight.bold : FontWeight.normal, | ||
), | ||
), | ||
trailing: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
IconButton( | ||
onPressed: () async { | ||
edit = !edit; | ||
if (!edit) { | ||
if (hasParticipant) { | ||
widget.participant!.pseudo = controller.text; | ||
await widget.participant!.conn.save(); | ||
} else { | ||
widget.participant = Participant( | ||
pseudo: controller.text, | ||
project: widget.project, | ||
); | ||
await widget.participant!.conn.save(); | ||
widget.project.participants.add(widget.participant!); | ||
widget.setHasNew(false); | ||
return; | ||
} | ||
} | ||
setState(() {}); | ||
}, | ||
icon: Icon(edit ? Icons.done : Icons.edit), | ||
), | ||
IconButton( | ||
icon: const Icon(Icons.close), | ||
onPressed: () async { | ||
if (hasParticipant) { | ||
await confirmBox( | ||
context: context, | ||
title: "Remove ${widget.participant!.pseudo}", | ||
content: | ||
"Are you sure you want to remove ${widget.participant!.pseudo}? You will not be able to undo it.", | ||
onValidate: () async { | ||
await widget.project | ||
.deleteParticipant(widget.participant!); | ||
widget.onChange(); | ||
if (context.mounted) Navigator.of(context).pop(); | ||
}, | ||
); | ||
} else { | ||
widget.setHasNew(false); | ||
} | ||
}), | ||
], | ||
), | ||
); | ||
} | ||
} |