mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-03 02:24:30 +01:00
Show entries graph in the category overview
This commit is contained in:
@@ -78,7 +78,7 @@ class MeasurementProvider with ChangeNotifier {
|
||||
MeasurementCategory editedCategory = category.copyWith(entries: loadedEntries);
|
||||
_categories.removeAt(categoryIndex);
|
||||
_categories.insert(categoryIndex, editedCategory);
|
||||
//notifyListeners();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Fetches and sets the measurement categories and their entries
|
||||
|
||||
@@ -20,10 +20,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/providers/measurement.dart';
|
||||
import 'package:wger/screens/form_screen.dart';
|
||||
import 'package:wger/screens/measurement_entries_screen.dart';
|
||||
|
||||
import 'forms.dart';
|
||||
import 'package:wger/widgets/core/charts.dart';
|
||||
|
||||
class CategoriesList extends StatelessWidget {
|
||||
@override
|
||||
@@ -35,73 +33,39 @@ class CategoriesList extends StatelessWidget {
|
||||
itemCount: _provider.categories.length,
|
||||
itemBuilder: (context, index) {
|
||||
final currentCategory = _provider.categories[index];
|
||||
|
||||
return Card(
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
MeasurementEntriesScreen.routeName,
|
||||
arguments: currentCategory.id,
|
||||
);
|
||||
},
|
||||
title: Text(currentCategory.name),
|
||||
subtitle: Text(currentCategory.unit),
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext contextDialog) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).confirmDelete(currentCategory.name),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
|
||||
onPressed: () => Navigator.of(contextDialog).pop(),
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
AppLocalizations.of(context).delete,
|
||||
style: TextStyle(color: Theme.of(context).errorColor),
|
||||
),
|
||||
onPressed: () {
|
||||
// Confirmed, delete the workout
|
||||
_provider.deleteCategory(currentCategory.id!);
|
||||
|
||||
// Close the popup
|
||||
Navigator.of(contextDialog).pop();
|
||||
|
||||
// and inform the user
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 5),
|
||||
child: Text(
|
||||
currentCategory.name,
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
color: Colors.white,
|
||||
padding: EdgeInsets.all(10),
|
||||
height: 220,
|
||||
child: MeasurementChartWidget(currentCategory.entries
|
||||
.map((e) => MeasurementChartEntry(e.value, e.date))
|
||||
.toList()),
|
||||
),
|
||||
Divider(),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: TextButton(
|
||||
child: Text(AppLocalizations.of(context).goToDetailPage),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
MeasurementEntriesScreen.routeName,
|
||||
arguments: currentCategory.id,
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: Icon(Icons.edit),
|
||||
onPressed: () async {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).edit,
|
||||
MeasurementCategoryForm(currentCategory),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -23,8 +23,10 @@ import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/models/measurements/measurement_category.dart';
|
||||
import 'package:wger/models/measurements/measurement_entry.dart';
|
||||
import 'package:wger/providers/measurement.dart';
|
||||
import 'package:wger/screens/measurement_categories_screen.dart';
|
||||
import 'package:wger/widgets/core/charts.dart';
|
||||
|
||||
import 'measurement_categories_screen_test.mocks.dart';
|
||||
|
||||
@@ -35,8 +37,14 @@ void main() {
|
||||
setUp(() {
|
||||
mockMeasurementProvider = MockMeasurementProvider();
|
||||
when(mockMeasurementProvider.categories).thenReturn([
|
||||
MeasurementCategory(id: 1, name: 'body fat', unit: '%'),
|
||||
MeasurementCategory(id: 2, name: 'biceps', unit: 'cm'),
|
||||
MeasurementCategory(id: 1, name: 'body fat', unit: '%', entries: [
|
||||
MeasurementEntry(id: 1, category: 1, date: DateTime(2021, 9, 1), value: 10, notes: ''),
|
||||
MeasurementEntry(id: 2, category: 1, date: DateTime(2021, 9, 5), value: 11, notes: ''),
|
||||
]),
|
||||
MeasurementCategory(id: 2, name: 'biceps', unit: 'cm', entries: [
|
||||
MeasurementEntry(id: 3, category: 2, date: DateTime(2021, 9, 1), value: 30, notes: ''),
|
||||
MeasurementEntry(id: 4, category: 2, date: DateTime(2021, 9, 5), value: 40, notes: ''),
|
||||
]),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -54,12 +62,12 @@ void main() {
|
||||
|
||||
testWidgets('Test the widgets on the measurement category screen', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createHomeScreen());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Measurement categories'), findsOneWidget);
|
||||
expect(find.text('body fat'), findsOneWidget);
|
||||
expect(find.text('%'), findsOneWidget);
|
||||
|
||||
expect(find.text('biceps'), findsOneWidget);
|
||||
expect(find.text('cm'), findsOneWidget);
|
||||
expect(find.byType(Card), findsNWidgets(2));
|
||||
expect(find.byType(MeasurementChartWidget), findsNWidgets(2));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user