Skip to content

Commit b0cae79

Browse files
committed
Merge branch 'ux_fixes_problem'
2 parents d478660 + 3f46277 commit b0cae79

File tree

4 files changed

+94
-138
lines changed

4 files changed

+94
-138
lines changed

lib/widgets/measurements/entries.dart

Lines changed: 39 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -52,72 +52,46 @@ class EntriesList extends StatelessWidget {
5252
final currentEntry = _category.entries[index];
5353
final provider = Provider.of<MeasurementProvider>(context, listen: false);
5454

55-
return Dismissible(
56-
key: Key(currentEntry.id.toString()),
57-
onDismissed: (direction) {
58-
if (direction == DismissDirection.endToStart) {
59-
// Delete entry from DB
60-
provider.deleteEntry(currentEntry.id!, currentEntry.category);
61-
62-
// and inform the user
63-
ScaffoldMessenger.of(context).showSnackBar(
64-
SnackBar(
65-
content: Text(
66-
AppLocalizations.of(context).successfullyDeleted,
67-
textAlign: TextAlign.center,
68-
),
69-
),
70-
);
71-
}
72-
},
73-
confirmDismiss: (direction) async {
74-
// Edit entry
75-
if (direction == DismissDirection.startToEnd) {
76-
Navigator.pushNamed(
77-
context,
78-
FormScreen.routeName,
79-
arguments: FormScreenArguments(
80-
AppLocalizations.of(context).edit,
81-
MeasurementEntryForm(currentEntry.category, currentEntry),
82-
),
83-
);
84-
return false;
85-
}
86-
return true;
87-
},
88-
secondaryBackground: Container(
89-
color: Theme.of(context).colorScheme.error,
90-
alignment: Alignment.centerRight,
91-
padding: const EdgeInsets.only(right: 20),
92-
margin: const EdgeInsets.symmetric(
93-
horizontal: 4,
94-
vertical: 4,
95-
),
96-
child: const Icon(
97-
Icons.delete,
98-
color: Colors.white,
99-
),
100-
),
101-
background: Container(
102-
color: wgerPrimaryButtonColor,
103-
alignment: Alignment.centerLeft,
104-
padding: const EdgeInsets.only(left: 20),
105-
margin: const EdgeInsets.symmetric(
106-
horizontal: 4,
107-
vertical: 4,
55+
return Card(
56+
child: ListTile(
57+
title: Text('${currentEntry.value} ${_category.unit}'),
58+
subtitle: Text(
59+
DateFormat.yMd(Localizations.localeOf(context).languageCode)
60+
.format(currentEntry.date),
10861
),
109-
child: const Icon(
110-
Icons.edit,
111-
color: Colors.white,
112-
),
113-
),
114-
child: Card(
115-
child: ListTile(
116-
title: Text('${currentEntry.value} ${_category.unit}'),
117-
subtitle: Text(
118-
DateFormat.yMd(Localizations.localeOf(context).languageCode)
119-
.format(currentEntry.date),
120-
),
62+
trailing: PopupMenuButton(
63+
itemBuilder: (BuildContext context) {
64+
return [
65+
PopupMenuItem(
66+
child: Text(AppLocalizations.of(context).edit),
67+
onTap: () => Navigator.pushNamed(
68+
context,
69+
FormScreen.routeName,
70+
arguments: FormScreenArguments(
71+
AppLocalizations.of(context).edit,
72+
MeasurementEntryForm(currentEntry.category, currentEntry),
73+
),
74+
)),
75+
PopupMenuItem(
76+
child: Text(AppLocalizations.of(context).delete),
77+
onTap: () async {
78+
// Delete entry from DB
79+
await provider.deleteEntry(currentEntry.id!, currentEntry.category);
80+
81+
// and inform the user
82+
if (context.mounted) {
83+
ScaffoldMessenger.of(context).showSnackBar(
84+
SnackBar(
85+
content: Text(
86+
AppLocalizations.of(context).successfullyDeleted,
87+
textAlign: TextAlign.center,
88+
),
89+
),
90+
);
91+
}
92+
})
93+
];
94+
},
12195
),
12296
),
12397
);

lib/widgets/weight/entries_list.dart

Lines changed: 40 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -60,72 +60,47 @@ class WeightEntriesList extends StatelessWidget {
6060
itemCount: weightProvider.items.length,
6161
itemBuilder: (context, index) {
6262
final currentEntry = weightProvider.items[index];
63-
return Dismissible(
64-
key: Key(currentEntry.id.toString()),
65-
onDismissed: (direction) {
66-
if (direction == DismissDirection.endToStart) {
67-
// Delete entry from DB
68-
weightProvider.deleteEntry(currentEntry.id!);
69-
70-
// and inform the user
71-
ScaffoldMessenger.of(context).showSnackBar(
72-
SnackBar(
73-
content: Text(
74-
AppLocalizations.of(context).successfullyDeleted,
75-
textAlign: TextAlign.center,
76-
),
77-
),
78-
);
79-
}
80-
},
81-
confirmDismiss: (direction) async {
82-
// Edit entry
83-
if (direction == DismissDirection.startToEnd) {
84-
Navigator.pushNamed(
85-
context,
86-
FormScreen.routeName,
87-
arguments: FormScreenArguments(
88-
AppLocalizations.of(context).edit,
89-
WeightForm(currentEntry),
90-
),
91-
);
92-
return false;
93-
}
94-
return true;
95-
},
96-
secondaryBackground: Container(
97-
color: Theme.of(context).colorScheme.error,
98-
alignment: Alignment.centerRight,
99-
padding: const EdgeInsets.only(right: 20),
100-
margin: const EdgeInsets.symmetric(
101-
horizontal: 4,
102-
vertical: 4,
103-
),
104-
child: const Icon(
105-
Icons.delete,
106-
color: Colors.white,
107-
),
108-
),
109-
background: Container(
110-
// color: wgerPrimaryButtonColor,
111-
alignment: Alignment.centerLeft,
112-
padding: const EdgeInsets.only(left: 20),
113-
margin: const EdgeInsets.symmetric(
114-
horizontal: 4,
115-
vertical: 4,
63+
return Card(
64+
child: ListTile(
65+
title: Text('${currentEntry.weight} kg'),
66+
subtitle: Text(
67+
DateFormat.yMd(Localizations.localeOf(context).languageCode)
68+
.format(currentEntry.date),
11669
),
117-
child: const Icon(
118-
Icons.edit,
119-
color: Colors.white,
120-
),
121-
),
122-
child: Card(
123-
child: ListTile(
124-
title: Text('${currentEntry.weight} kg'),
125-
subtitle: Text(
126-
DateFormat.yMd(Localizations.localeOf(context).languageCode)
127-
.format(currentEntry.date),
128-
),
70+
trailing: PopupMenuButton(
71+
itemBuilder: (BuildContext context) {
72+
return [
73+
PopupMenuItem(
74+
child: Text(AppLocalizations.of(context).edit),
75+
onTap: () => Navigator.pushNamed(
76+
context,
77+
FormScreen.routeName,
78+
arguments: FormScreenArguments(
79+
AppLocalizations.of(context).edit,
80+
WeightForm(currentEntry),
81+
),
82+
)),
83+
PopupMenuItem(
84+
child: Text(AppLocalizations.of(context).delete),
85+
onTap: () async {
86+
// Delete entry from DB
87+
await weightProvider.deleteEntry(currentEntry.id!);
88+
89+
// and inform the user
90+
if (context.mounted) {
91+
ScaffoldMessenger.of(context).showSnackBar(
92+
SnackBar(
93+
content: Text(
94+
AppLocalizations.of(context).successfullyDeleted,
95+
textAlign: TextAlign.center,
96+
),
97+
),
98+
);
99+
}
100+
},
101+
)
102+
];
103+
},
129104
),
130105
),
131106
);

test/weight/weight_provider_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import 'weight_provider_test.mocks.dart';
3131

3232
@GenerateMocks([WgerBaseProvider])
3333
void main() {
34-
var mockBaseProvider = MockWgerBaseProvider();
34+
late MockWgerBaseProvider mockBaseProvider;
3535

3636
setUp(() {
3737
mockBaseProvider = MockWgerBaseProvider();

test/weight/weight_screen_test.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ import 'weight_screen_test.mocks.dart';
3333

3434
@GenerateMocks([BodyWeightProvider])
3535
void main() {
36-
var mockWeightProvider = MockBodyWeightProvider();
36+
late MockBodyWeightProvider mockWeightProvider;
3737

38-
Widget createWeightScreen({locale = 'en'}) {
38+
setUp(() {
3939
mockWeightProvider = MockBodyWeightProvider();
4040
when(mockWeightProvider.items).thenReturn(getWeightEntries());
41+
});
4142

43+
Widget createWeightScreen({locale = 'en'}) {
4244
return ChangeNotifierProvider<BodyWeightProvider>(
4345
create: (context) => mockWeightProvider,
4446
child: MaterialApp(
@@ -58,17 +60,23 @@ void main() {
5860

5961
expect(find.text('Weight'), findsOneWidget);
6062
expect(find.byType(MeasurementChartWidgetFl), findsOneWidget);
61-
expect(find.byType(Dismissible), findsNWidgets(2));
63+
expect(find.byType(Card), findsNWidgets(2));
6264
expect(find.byType(ListTile), findsNWidgets(2));
6365
});
6466

65-
testWidgets('Test deleting an item by dragging the dismissible', (WidgetTester tester) async {
67+
testWidgets('Test deleting an item using the Delete button', (WidgetTester tester) async {
68+
// Arrange
6669
await tester.pumpWidget(createWeightScreen());
6770

68-
await tester.drag(find.byKey(const Key('1')), const Offset(-500.0, 0.0));
71+
// Act
72+
expect(find.byType(ListTile), findsNWidgets(2));
73+
await tester.tap(find.byTooltip('Show menu').first);
74+
await tester.pumpAndSettle();
75+
76+
// Assert
77+
await tester.tap(find.text('Delete'));
6978
await tester.pumpAndSettle();
7079
verify(mockWeightProvider.deleteEntry(1)).called(1);
71-
expect(find.byType(ListTile), findsOneWidget);
7280
});
7381

7482
testWidgets('Test the form on the body weight screen', (WidgetTester tester) async {
@@ -83,7 +91,6 @@ void main() {
8391
testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async {
8492
await tester.pumpWidget(createWeightScreen());
8593

86-
// One in the entries list, one in the chart
8794
expect(find.text('1/1/2021'), findsOneWidget);
8895
expect(find.text('1/10/2021'), findsOneWidget);
8996
});

0 commit comments

Comments
 (0)