Skip to content

Commit 268fe0e

Browse files
committed
Fix many issues
1 parent 5248ffc commit 268fe0e

File tree

13 files changed

+202
-185
lines changed

13 files changed

+202
-185
lines changed

lib/components/pages/new_project/new_project_page.dart

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import '../../../model/project_data.dart';
99
import '../../../utils/navigator/navigator.dart';
1010
import '../../../utils/switches/text_switch.dart';
1111
import '../../../utils/tiles/header_tile.dart';
12-
import '../../../utils/tiles/participant_tile.dart';
12+
import 'participant_tile.dart';
1313
import '../instances/instances_list_page.dart';
1414

1515
class NewProjectPage extends StatefulWidget {
@@ -44,6 +44,7 @@ class _NewProjectPageState extends State<NewProjectPage> {
4444
children: [
4545
Expanded(
4646
child: SelectFormField(
47+
enabled: widget.project == null,
4748
validator: (value) => value == null || value.isEmpty
4849
? 'You must select a project instance!'
4950
: null,
@@ -62,17 +63,20 @@ class _NewProjectPageState extends State<NewProjectPage> {
6263
widget.projectData.instance = Instance.fromName(v);
6364
});
6465
},
65-
decoration: const InputDecoration(
66+
decoration: InputDecoration(
6667
labelText: "Project instance",
67-
border: OutlineInputBorder(),
68-
suffixIcon: Icon(Icons.arrow_drop_down),
68+
border: const OutlineInputBorder(),
69+
suffixIcon: const Icon(Icons.arrow_drop_down),
70+
labelStyle:
71+
TextStyle(color: Theme.of(context).colorScheme.onPrimary),
6972
),
7073
),
7174
),
7275
const SizedBox(width: 5),
7376
IconButton(
74-
onPressed: () {
75-
navigatorPush(context, () => const InstancesListPage());
77+
onPressed: () async {
78+
await navigatorPush(context, () => const InstancesListPage());
79+
setState(() {});
7680
},
7781
icon: const Icon(Icons.settings),
7882
),
@@ -99,19 +103,58 @@ class _NewProjectPageState extends State<NewProjectPage> {
99103
border: const OutlineInputBorder(),
100104
),
101105
),
106+
if (widget.project != null)
107+
const SizedBox(
108+
height: 12,
109+
),
110+
if (widget.project != null)
111+
SelectFormField(
112+
type: SelectFormFieldType.dropdown,
113+
initialValue:
114+
widget.project!.currentParticipant?.pseudo ?? "anonymous",
115+
items: [
116+
...widget.project!.participants.map<Map<String, dynamic>>((e) => {
117+
'value': e.pseudo,
118+
}),
119+
const {'value': 'anonymous', 'label': 'Anonymous'},
120+
],
121+
onChanged: (v) {
122+
setState(() {
123+
if (v == 'anonymous') {
124+
widget.project!.currentParticipant = null;
125+
widget.project!.currentParticipantId = null;
126+
} else {
127+
widget.project!.currentParticipant =
128+
widget.project!.participantByPseudo(v);
129+
widget.project!.currentParticipantId =
130+
widget.project!.currentParticipant?.localId;
131+
}
132+
});
133+
},
134+
decoration: const InputDecoration(
135+
labelText: "Who are you ?",
136+
border: OutlineInputBorder(),
137+
suffixIcon: Icon(Icons.arrow_drop_down),
138+
),
139+
),
102140
const SizedBox(
103141
height: 12,
104142
),
105-
if (widget.project != null) ParticipantListWidget(widget.project!),
143+
if (widget.project != null)
144+
ParticipantListWidget(
145+
widget.project!,
146+
reloadParent: () => setState(() {}),
147+
),
106148
]),
107149
);
108150
}
109151
}
110152

111153
class ParticipantListWidget extends StatefulWidget {
112-
const ParticipantListWidget(this.project, {super.key});
154+
const ParticipantListWidget(this.project, {super.key, this.reloadParent});
113155

114156
final Project project;
157+
final Function()? reloadParent;
115158

116159
@override
117160
State<ParticipantListWidget> createState() => _ParticipantListWidgetState();
@@ -140,7 +183,7 @@ class _ParticipantListWidgetState extends State<ParticipantListWidget> {
140183
? null
141184
: widget.project.participants.elementAt(index),
142185
setHasNew: setHasNew,
143-
onChange: () => setState(() {}),
186+
onChange: widget.reloadParent ?? () => setState(() {}),
144187
),
145188
itemCount: widget.project.participants.length + (hasNew ? 1 : 0),
146189
),

lib/utils/tiles/participant_tile.dart renamed to lib/components/pages/new_project/participant_tile.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter/services.dart';
33

4-
import '../../model/participant.dart';
5-
import '../../model/project.dart';
6-
import '../dialogs/confirm_box.dart';
4+
import '../../../model/participant.dart';
5+
import '../../../model/project.dart';
6+
import '../../../utils/dialogs/confirm_box.dart';
77

88
class ParticipantTile extends StatefulWidget {
99
ParticipantTile({
@@ -33,12 +33,8 @@ class _ParticipantTileState extends State<ParticipantTile> {
3333
bool hasParticipant = widget.participant != null;
3434
if (!hasParticipant) edit = true;
3535

36-
bool isMe = widget.participant == widget.project.currentParticipant;
37-
3836
controller = TextEditingController(
39-
text: hasParticipant
40-
? widget.participant!.pseudo + (isMe && !edit ? ' (me)' : '')
41-
: '',
37+
text: hasParticipant ? widget.participant!.pseudo : '',
4238
);
4339

4440
return ListTile(
@@ -57,9 +53,6 @@ class _ParticipantTileState extends State<ParticipantTile> {
5753
border: edit ? null : InputBorder.none,
5854
),
5955
controller: controller,
60-
style: TextStyle(
61-
fontWeight: isMe ? FontWeight.bold : FontWeight.normal,
62-
),
6356
),
6457
trailing: Row(
6558
mainAxisSize: MainAxisSize.min,
@@ -82,7 +75,7 @@ class _ParticipantTileState extends State<ParticipantTile> {
8275
return;
8376
}
8477
}
85-
setState(() {});
78+
widget.onChange();
8679
},
8780
icon: Icon(edit ? Icons.done : Icons.edit),
8881
),
@@ -98,6 +91,11 @@ class _ParticipantTileState extends State<ParticipantTile> {
9891
onValidate: () async {
9992
await widget.project
10093
.deleteParticipant(widget.participant!);
94+
if (widget.project.currentParticipant ==
95+
widget.participant) {
96+
widget.project.currentParticipant = null;
97+
widget.project.currentParticipantId = null;
98+
}
10199
widget.onChange();
102100
if (context.mounted) Navigator.of(context).pop();
103101
},

lib/components/pages/project/balances/balancing_page_part.dart

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,19 @@ class _BalancingPagePartState extends State<BalancingPagePart> {
3939
double w = MediaQuery.of(context).size.width / 2;
4040
bool isMe = widget.project.currentParticipant == p;
4141
items.add(
42-
GestureDetector(
43-
onTap: () async {
44-
widget.project.currentParticipant = p;
45-
widget.project.currentParticipantId = p.localId;
46-
widget.project.conn.save();
47-
setState(() {});
48-
},
49-
child: Padding(
50-
padding: isMe
51-
? const EdgeInsets.only(top: 5, bottom: 10)
52-
: const EdgeInsets.symmetric(vertical: 5),
53-
child: CustomPaint(
54-
painter: SharePainter(
55-
participant: p,
56-
share: parts[p]!,
57-
isMe: isMe,
58-
maxShare: maxShare,
59-
screenW: w,
60-
),
61-
child: Container(height: 30),
42+
Padding(
43+
padding: isMe
44+
? const EdgeInsets.only(top: 5, bottom: 10)
45+
: const EdgeInsets.symmetric(vertical: 5),
46+
child: CustomPaint(
47+
painter: SharePainter(
48+
participant: p,
49+
share: parts[p]!,
50+
isMe: isMe,
51+
maxShare: maxShare,
52+
screenW: w,
6253
),
54+
child: Container(height: 30),
6355
),
6456
),
6557
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'package:flutter/material.dart';
2+
3+
class TableHeaderCell extends StatelessWidget {
4+
const TableHeaderCell({super.key, required this.text});
5+
6+
final String text;
7+
8+
@override
9+
Widget build(BuildContext context) {
10+
return TableCell(
11+
verticalAlignment: TableCellVerticalAlignment.middle,
12+
child: Text(
13+
text,
14+
textAlign: TextAlign.left,
15+
style: const TextStyle(
16+
fontWeight: FontWeight.bold,
17+
),
18+
),
19+
);
20+
}
21+
}

0 commit comments

Comments
 (0)