@@ -7,6 +7,8 @@ import 'package:shared/model/participant.dart';
77
88import '../../model/project.dart' ;
99import '../../model/project_data.dart' ;
10+ import '../../utils/tiles/header_tile.dart' ;
11+ import '../../utils/tiles/participant_tile.dart' ;
1012import 'new_project/local.dart' ;
1113import 'new_project/pocketbase.dart' ;
1214
@@ -127,155 +129,3 @@ class _ParticipantListWidgetState extends State<ParticipantListWidget> {
127129 );
128130 }
129131}
130-
131- class HeaderTile extends StatelessWidget {
132- const HeaderTile (this .text, {super .key});
133-
134- final String text;
135-
136- @override
137- Widget build (BuildContext context) {
138- return ListTile (
139- title: Text (
140- text,
141- style: const TextStyle (
142- fontFeatures: [FontFeature .enable ('smcp' )],
143- ),
144- ),
145- tileColor: Theme .of (context).splashColor,
146- dense: false ,
147- );
148- }
149- }
150-
151- class ParticipantTile extends StatefulWidget {
152- ParticipantTile ({
153- super .key,
154- required this .project,
155- required this .participant,
156- required this .onChange,
157- required this .setHasNew,
158- });
159-
160- final Project project;
161- Participant ? participant;
162- final Function () onChange;
163- final void Function (bool v) setHasNew;
164-
165- @override
166- State <ParticipantTile > createState () => _ParticipantTileState ();
167- }
168-
169- class _ParticipantTileState extends State <ParticipantTile > {
170- late TextEditingController controller;
171-
172- bool edit = false ;
173-
174- @override
175- Widget build (BuildContext context) {
176- bool hasParticipant = widget.participant != null ;
177- if (! hasParticipant) edit = true ;
178-
179- bool isMe = widget.participant == widget.project.currentParticipant;
180-
181- controller = TextEditingController (
182- text: hasParticipant
183- ? widget.participant! .pseudo + (isMe && ! edit ? ' (me)' : '' )
184- : '' ,
185- );
186-
187- return ListTile (
188- onTap: () {
189- widget.project.currentParticipant = widget.participant;
190- widget.onChange ();
191- },
192- title: TextField (
193- autofocus: true ,
194- enabled: edit,
195- maxLines: 1 ,
196- maxLength: 30 ,
197- maxLengthEnforcement: MaxLengthEnforcement .enforced,
198- decoration: InputDecoration (
199- counterText: "" ,
200- border: edit ? null : InputBorder .none,
201- ),
202- controller: controller,
203- style: TextStyle (
204- fontWeight: isMe ? FontWeight .bold : FontWeight .normal,
205- ),
206- ),
207- trailing: Row (
208- mainAxisSize: MainAxisSize .min,
209- children: [
210- IconButton (
211- onPressed: () async {
212- edit = ! edit;
213- if (! edit) {
214- if (hasParticipant) {
215- widget.participant! .pseudo = controller.text;
216- await widget.participant! .conn.save ();
217- } else {
218- widget.participant = Participant (
219- pseudo: controller.text,
220- project: widget.project,
221- );
222- await widget.participant! .conn.save ();
223- widget.project.participants.add (widget.participant! );
224- widget.setHasNew (false );
225- return ;
226- }
227- }
228- setState (() {});
229- },
230- icon: Icon (edit ? Icons .done : Icons .edit),
231- ),
232- IconButton (
233- icon: const Icon (Icons .close),
234- onPressed: () async {
235- if (hasParticipant) {
236- await confirmBox (
237- context: context,
238- title: "Remove ${widget .participant !.pseudo }" ,
239- content:
240- "Are you sure you want to remove ${widget .participant !.pseudo }? You will not be able to undo it." ,
241- onValidate: () async {
242- await widget.project
243- .deleteParticipant (widget.participant! );
244- widget.onChange ();
245- if (context.mounted) Navigator .of (context).pop ();
246- },
247- );
248- } else {
249- widget.setHasNew (false );
250- }
251- }),
252- ],
253- ),
254- );
255- }
256-
257- Future <dynamic > confirmBox ({
258- required BuildContext context,
259- required String title,
260- required String content,
261- required Function ()? onValidate,
262- }) {
263- return showDialog (
264- context: context,
265- builder: (context) => AlertDialog (
266- title: Text (title),
267- content: Text (content),
268- actions: [
269- TextButton (
270- onPressed: onValidate,
271- child: const Text ("Yes" ),
272- ),
273- TextButton (
274- onPressed: () => Navigator .of (context).pop (),
275- child: const Text ("No" ),
276- ),
277- ],
278- ),
279- );
280- }
281- }
0 commit comments