Skip to content

Commit

Permalink
Fix many issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BhasherBEL committed Jun 9, 2023
1 parent 5248ffc commit 268fe0e
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 185 deletions.
61 changes: 52 additions & 9 deletions lib/components/pages/new_project/new_project_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '../../../model/project_data.dart';
import '../../../utils/navigator/navigator.dart';
import '../../../utils/switches/text_switch.dart';
import '../../../utils/tiles/header_tile.dart';
import '../../../utils/tiles/participant_tile.dart';
import 'participant_tile.dart';
import '../instances/instances_list_page.dart';

class NewProjectPage extends StatefulWidget {
Expand Down Expand Up @@ -44,6 +44,7 @@ class _NewProjectPageState extends State<NewProjectPage> {
children: [
Expanded(
child: SelectFormField(
enabled: widget.project == null,
validator: (value) => value == null || value.isEmpty
? 'You must select a project instance!'
: null,
Expand All @@ -62,17 +63,20 @@ class _NewProjectPageState extends State<NewProjectPage> {
widget.projectData.instance = Instance.fromName(v);
});
},
decoration: const InputDecoration(
decoration: InputDecoration(
labelText: "Project instance",
border: OutlineInputBorder(),
suffixIcon: Icon(Icons.arrow_drop_down),
border: const OutlineInputBorder(),
suffixIcon: const Icon(Icons.arrow_drop_down),
labelStyle:
TextStyle(color: Theme.of(context).colorScheme.onPrimary),
),
),
),
const SizedBox(width: 5),
IconButton(
onPressed: () {
navigatorPush(context, () => const InstancesListPage());
onPressed: () async {
await navigatorPush(context, () => const InstancesListPage());
setState(() {});
},
icon: const Icon(Icons.settings),
),
Expand All @@ -99,19 +103,58 @@ class _NewProjectPageState extends State<NewProjectPage> {
border: const OutlineInputBorder(),
),
),
if (widget.project != null)
const SizedBox(
height: 12,
),
if (widget.project != null)
SelectFormField(
type: SelectFormFieldType.dropdown,
initialValue:
widget.project!.currentParticipant?.pseudo ?? "anonymous",
items: [
...widget.project!.participants.map<Map<String, dynamic>>((e) => {
'value': e.pseudo,
}),
const {'value': 'anonymous', 'label': 'Anonymous'},
],
onChanged: (v) {
setState(() {
if (v == 'anonymous') {
widget.project!.currentParticipant = null;
widget.project!.currentParticipantId = null;
} else {
widget.project!.currentParticipant =
widget.project!.participantByPseudo(v);
widget.project!.currentParticipantId =
widget.project!.currentParticipant?.localId;
}
});
},
decoration: const InputDecoration(
labelText: "Who are you ?",
border: OutlineInputBorder(),
suffixIcon: Icon(Icons.arrow_drop_down),
),
),
const SizedBox(
height: 12,
),
if (widget.project != null) ParticipantListWidget(widget.project!),
if (widget.project != null)
ParticipantListWidget(
widget.project!,
reloadParent: () => setState(() {}),
),
]),
);
}
}

class ParticipantListWidget extends StatefulWidget {
const ParticipantListWidget(this.project, {super.key});
const ParticipantListWidget(this.project, {super.key, this.reloadParent});

final Project project;
final Function()? reloadParent;

@override
State<ParticipantListWidget> createState() => _ParticipantListWidgetState();
Expand Down Expand Up @@ -140,7 +183,7 @@ class _ParticipantListWidgetState extends State<ParticipantListWidget> {
? null
: widget.project.participants.elementAt(index),
setHasNew: setHasNew,
onChange: () => setState(() {}),
onChange: widget.reloadParent ?? () => setState(() {}),
),
itemCount: widget.project.participants.length + (hasNew ? 1 : 0),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../../model/participant.dart';
import '../../model/project.dart';
import '../dialogs/confirm_box.dart';
import '../../../model/participant.dart';
import '../../../model/project.dart';
import '../../../utils/dialogs/confirm_box.dart';

class ParticipantTile extends StatefulWidget {
ParticipantTile({
Expand Down Expand Up @@ -33,12 +33,8 @@ class _ParticipantTileState extends State<ParticipantTile> {
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)' : '')
: '',
text: hasParticipant ? widget.participant!.pseudo : '',
);

return ListTile(
Expand All @@ -57,9 +53,6 @@ class _ParticipantTileState extends State<ParticipantTile> {
border: edit ? null : InputBorder.none,
),
controller: controller,
style: TextStyle(
fontWeight: isMe ? FontWeight.bold : FontWeight.normal,
),
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
Expand All @@ -82,7 +75,7 @@ class _ParticipantTileState extends State<ParticipantTile> {
return;
}
}
setState(() {});
widget.onChange();
},
icon: Icon(edit ? Icons.done : Icons.edit),
),
Expand All @@ -98,6 +91,11 @@ class _ParticipantTileState extends State<ParticipantTile> {
onValidate: () async {
await widget.project
.deleteParticipant(widget.participant!);
if (widget.project.currentParticipant ==
widget.participant) {
widget.project.currentParticipant = null;
widget.project.currentParticipantId = null;
}
widget.onChange();
if (context.mounted) Navigator.of(context).pop();
},
Expand Down
32 changes: 12 additions & 20 deletions lib/components/pages/project/balances/balancing_page_part.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,19 @@ class _BalancingPagePartState extends State<BalancingPagePart> {
double w = MediaQuery.of(context).size.width / 2;
bool isMe = widget.project.currentParticipant == p;
items.add(
GestureDetector(
onTap: () async {
widget.project.currentParticipant = p;
widget.project.currentParticipantId = p.localId;
widget.project.conn.save();
setState(() {});
},
child: Padding(
padding: isMe
? const EdgeInsets.only(top: 5, bottom: 10)
: const EdgeInsets.symmetric(vertical: 5),
child: CustomPaint(
painter: SharePainter(
participant: p,
share: parts[p]!,
isMe: isMe,
maxShare: maxShare,
screenW: w,
),
child: Container(height: 30),
Padding(
padding: isMe
? const EdgeInsets.only(top: 5, bottom: 10)
: const EdgeInsets.symmetric(vertical: 5),
child: CustomPaint(
painter: SharePainter(
participant: p,
share: parts[p]!,
isMe: isMe,
maxShare: maxShare,
screenW: w,
),
child: Container(height: 30),
),
),
);
Expand Down
21 changes: 21 additions & 0 deletions lib/components/pages/project/expenses/entry_table.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/material.dart';

class TableHeaderCell extends StatelessWidget {
const TableHeaderCell({super.key, required this.text});

final String text;

@override
Widget build(BuildContext context) {
return TableCell(
verticalAlignment: TableCellVerticalAlignment.middle,
child: Text(
text,
textAlign: TextAlign.left,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
);
}
}
Loading

0 comments on commit 268fe0e

Please sign in to comment.