mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Merge branch 'ux_fixes_problem'
This commit is contained in:
@@ -52,72 +52,46 @@ class EntriesList extends StatelessWidget {
|
||||
final currentEntry = _category.entries[index];
|
||||
final provider = Provider.of<MeasurementProvider>(context, listen: false);
|
||||
|
||||
return Dismissible(
|
||||
key: Key(currentEntry.id.toString()),
|
||||
onDismissed: (direction) {
|
||||
if (direction == DismissDirection.endToStart) {
|
||||
// Delete entry from DB
|
||||
provider.deleteEntry(currentEntry.id!, currentEntry.category);
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text('${currentEntry.value} ${_category.unit}'),
|
||||
subtitle: Text(
|
||||
DateFormat.yMd(Localizations.localeOf(context).languageCode)
|
||||
.format(currentEntry.date),
|
||||
),
|
||||
trailing: PopupMenuButton(
|
||||
itemBuilder: (BuildContext context) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
child: Text(AppLocalizations.of(context).edit),
|
||||
onTap: () => Navigator.pushNamed(
|
||||
context,
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).edit,
|
||||
MeasurementEntryForm(currentEntry.category, currentEntry),
|
||||
),
|
||||
)),
|
||||
PopupMenuItem(
|
||||
child: Text(AppLocalizations.of(context).delete),
|
||||
onTap: () async {
|
||||
// Delete entry from DB
|
||||
await provider.deleteEntry(currentEntry.id!, currentEntry.category);
|
||||
|
||||
// and inform the user
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
confirmDismiss: (direction) async {
|
||||
// Edit entry
|
||||
if (direction == DismissDirection.startToEnd) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).edit,
|
||||
MeasurementEntryForm(currentEntry.category, currentEntry),
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
secondaryBackground: Container(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 4,
|
||||
vertical: 4,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.delete,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
background: Container(
|
||||
color: wgerPrimaryButtonColor,
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.only(left: 20),
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 4,
|
||||
vertical: 4,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.edit,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
child: Card(
|
||||
child: ListTile(
|
||||
title: Text('${currentEntry.value} ${_category.unit}'),
|
||||
subtitle: Text(
|
||||
DateFormat.yMd(Localizations.localeOf(context).languageCode)
|
||||
.format(currentEntry.date),
|
||||
),
|
||||
// and inform the user
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
})
|
||||
];
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -60,72 +60,47 @@ class WeightEntriesList extends StatelessWidget {
|
||||
itemCount: weightProvider.items.length,
|
||||
itemBuilder: (context, index) {
|
||||
final currentEntry = weightProvider.items[index];
|
||||
return Dismissible(
|
||||
key: Key(currentEntry.id.toString()),
|
||||
onDismissed: (direction) {
|
||||
if (direction == DismissDirection.endToStart) {
|
||||
// Delete entry from DB
|
||||
weightProvider.deleteEntry(currentEntry.id!);
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text('${currentEntry.weight} kg'),
|
||||
subtitle: Text(
|
||||
DateFormat.yMd(Localizations.localeOf(context).languageCode)
|
||||
.format(currentEntry.date),
|
||||
),
|
||||
trailing: PopupMenuButton(
|
||||
itemBuilder: (BuildContext context) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
child: Text(AppLocalizations.of(context).edit),
|
||||
onTap: () => Navigator.pushNamed(
|
||||
context,
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).edit,
|
||||
WeightForm(currentEntry),
|
||||
),
|
||||
)),
|
||||
PopupMenuItem(
|
||||
child: Text(AppLocalizations.of(context).delete),
|
||||
onTap: () async {
|
||||
// Delete entry from DB
|
||||
await weightProvider.deleteEntry(currentEntry.id!);
|
||||
|
||||
// and inform the user
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
confirmDismiss: (direction) async {
|
||||
// Edit entry
|
||||
if (direction == DismissDirection.startToEnd) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).edit,
|
||||
WeightForm(currentEntry),
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
secondaryBackground: Container(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 4,
|
||||
vertical: 4,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.delete,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
background: Container(
|
||||
// color: wgerPrimaryButtonColor,
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.only(left: 20),
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 4,
|
||||
vertical: 4,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.edit,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
child: Card(
|
||||
child: ListTile(
|
||||
title: Text('${currentEntry.weight} kg'),
|
||||
subtitle: Text(
|
||||
DateFormat.yMd(Localizations.localeOf(context).languageCode)
|
||||
.format(currentEntry.date),
|
||||
),
|
||||
// and inform the user
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
)
|
||||
];
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -31,7 +31,7 @@ import 'weight_provider_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([WgerBaseProvider])
|
||||
void main() {
|
||||
var mockBaseProvider = MockWgerBaseProvider();
|
||||
late MockWgerBaseProvider mockBaseProvider;
|
||||
|
||||
setUp(() {
|
||||
mockBaseProvider = MockWgerBaseProvider();
|
||||
|
||||
@@ -33,12 +33,14 @@ import 'weight_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([BodyWeightProvider])
|
||||
void main() {
|
||||
var mockWeightProvider = MockBodyWeightProvider();
|
||||
late MockBodyWeightProvider mockWeightProvider;
|
||||
|
||||
Widget createWeightScreen({locale = 'en'}) {
|
||||
setUp(() {
|
||||
mockWeightProvider = MockBodyWeightProvider();
|
||||
when(mockWeightProvider.items).thenReturn(getWeightEntries());
|
||||
});
|
||||
|
||||
Widget createWeightScreen({locale = 'en'}) {
|
||||
return ChangeNotifierProvider<BodyWeightProvider>(
|
||||
create: (context) => mockWeightProvider,
|
||||
child: MaterialApp(
|
||||
@@ -58,17 +60,23 @@ void main() {
|
||||
|
||||
expect(find.text('Weight'), findsOneWidget);
|
||||
expect(find.byType(MeasurementChartWidgetFl), findsOneWidget);
|
||||
expect(find.byType(Dismissible), findsNWidgets(2));
|
||||
expect(find.byType(Card), findsNWidgets(2));
|
||||
expect(find.byType(ListTile), findsNWidgets(2));
|
||||
});
|
||||
|
||||
testWidgets('Test deleting an item by dragging the dismissible', (WidgetTester tester) async {
|
||||
testWidgets('Test deleting an item using the Delete button', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
await tester.pumpWidget(createWeightScreen());
|
||||
|
||||
await tester.drag(find.byKey(const Key('1')), const Offset(-500.0, 0.0));
|
||||
// Act
|
||||
expect(find.byType(ListTile), findsNWidgets(2));
|
||||
await tester.tap(find.byTooltip('Show menu').first);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
await tester.tap(find.text('Delete'));
|
||||
await tester.pumpAndSettle();
|
||||
verify(mockWeightProvider.deleteEntry(1)).called(1);
|
||||
expect(find.byType(ListTile), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Test the form on the body weight screen', (WidgetTester tester) async {
|
||||
@@ -83,7 +91,6 @@ void main() {
|
||||
testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createWeightScreen());
|
||||
|
||||
// One in the entries list, one in the chart
|
||||
expect(find.text('1/1/2021'), findsOneWidget);
|
||||
expect(find.text('1/10/2021'), findsOneWidget);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user