Files
flutter/lib/core/dashboard.dart
Roland Geider 2d9b8cadb6 Reorder imports
dart fix --apply --code=directives_ordering
2026-09-03 20:42:06 +02:00

102 lines
3.8 KiB
Dart

/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2020 - 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:material_ui/material_ui.dart';
import 'package:wger/core/app_settings_notifier.dart';
import 'package:wger/core/material.dart';
import 'package:wger/core/widgets/app_bar.dart';
import 'package:wger/core/widgets/dashboard/calendar.dart';
import 'package:wger/core/widgets/dashboard/widgets/measurements.dart';
import 'package:wger/core/widgets/dashboard/widgets/nutrition.dart';
import 'package:wger/core/widgets/dashboard/widgets/routines.dart';
import 'package:wger/core/widgets/dashboard/widgets/trophies.dart';
import 'package:wger/core/widgets/dashboard/widgets/weight.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
class DashboardScreen extends ConsumerWidget {
const DashboardScreen({super.key});
static const routeName = '/dashboard';
Widget _getDashboardWidget(DashboardWidget widget) {
switch (widget) {
case DashboardWidget.routines:
return const DashboardRoutineWidget();
case DashboardWidget.weight:
return const DashboardWeightWidget();
case DashboardWidget.measurements:
return const DashboardMeasurementWidget();
case DashboardWidget.calendar:
return const DashboardCalendarWidget();
case DashboardWidget.nutrition:
return const DashboardNutritionWidget();
case DashboardWidget.trophies:
return const DashboardTrophiesWidget();
}
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final width = MediaQuery.sizeOf(context).width;
final isMobile = width < MATERIAL_XS_BREAKPOINT;
final visibleWidgets = ref.watch(
appSettingsProvider.select(
(s) => (s.value?.dashboardItems ?? defaultDashboardItems).visibleWidgets,
),
);
late final int crossAxisCount;
if (width < MATERIAL_XS_BREAKPOINT) {
crossAxisCount = 1;
} else if (width < MATERIAL_MD_BREAKPOINT) {
crossAxisCount = 2;
} else if (width < MATERIAL_LG_BREAKPOINT) {
crossAxisCount = 3;
} else {
crossAxisCount = 4;
}
return Scaffold(
appBar: MainAppBar(AppLocalizations.of(context).labelDashboard),
body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: MATERIAL_LG_BREAKPOINT),
child: isMobile
? ListView.builder(
padding: const EdgeInsets.all(10),
itemBuilder: (context, index) => _getDashboardWidget(visibleWidgets[index]),
itemCount: visibleWidgets.length,
)
: GridView.builder(
padding: const EdgeInsets.all(10),
itemBuilder: (context, index) => SingleChildScrollView(
child: _getDashboardWidget(visibleWidgets[index]),
),
itemCount: visibleWidgets.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount,
childAspectRatio: 0.7,
),
),
),
),
);
}
}