Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Rework home cards and nutrition widget rendering
InlitXa70c9d95c8d2
diff --git a/lib/app/app_shell.dart b/lib/app/app_shell.dartindex 87f35c4..fb54d6a 100644--- a/lib/app/app_shell.dart+++ b/lib/app/app_shell.dart@@ -130,8 +130,12 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Single}void _openFromWidget(String route) {- if (!mounted || !fit.onboarded || route != 'nutrition' || fit.isSessionActive) return;- if (fit.route != 'nutrition') fit.goNutrition();+ if (!mounted || !fit.onboarded || fit.isSessionActive) return;+ if (route == 'play') {+ playWorkout(context);+ } else if (route == 'nutrition' && fit.route != 'nutrition') {+ fit.goNutrition();+ }}void _showStepsInfo() {@@ -793,6 +797,19 @@ class _ParkedPill extends StatelessWidget {}}+void playWorkout(BuildContext context) {+ if (fit.sessionParked) {+ fit.stepBackIntoSession();+ return;+ }+ final planned = fit.todayRoutine;+ if (planned != null && planned.exerciseIds.isNotEmpty) {+ fit.startRoutine(planned);+ return;+ }+ showStartSheet(context);+}+class _NavBar extends StatefulWidget {const _NavBar();@@ -991,18 +1008,7 @@ class _NavBarState extends State<_NavBar> {);}- void _play(BuildContext context) {- if (fit.sessionParked) {- fit.stepBackIntoSession();- return;- }- final planned = fit.todayRoutine;- if (planned != null && planned.exerciseIds.isNotEmpty) {- fit.startRoutine(planned);- return;- }- showStartSheet(context);- }+ void _play(BuildContext context) => playWorkout(context);Widget _fab(BuildContext context) {final gc = context.gc;diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dartindex 38593a5..239d19d 100644--- a/lib/screens/home_screen.dart+++ b/lib/screens/home_screen.dart@@ -4,6 +4,7 @@ import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';import '../l10n/l10n.dart';import '../models/exercise.dart';+import '../models/workout.dart';import '../state/fit_state.dart';import '../theme/app_colors.dart';import '../theme/app_theme.dart';@@ -48,21 +49,31 @@ class HomeScreen extends StatelessWidget {ScrollAway(radius: 26, child: _hero(context, gc)),const SizedBox(height: 14),],- _away(_weekCard(context, gc)),- if (fit.stepsOn && fit.stepsAvailable) ...[- const SizedBox(height: 14),- _away(StepsCard()),- ],if (fit.photoDue) ...[const SizedBox(height: 14),_away(_photoNudge(gc)),],+ ..._homeBlocks(context, gc, routines, recommended),+ ]),+ ),+ ),+ ),+ );+ }++ List<Widget> _homeBlocks(BuildContext context, GymColors gc, List<Routine> routines, List<Exercise> recommended) {+ final blocks = <String, List<Widget>>{+ 'weekdays': [_away(_weekCard(context, gc))],+ 'steps': [+ if (fit.stepsOn && fit.stepsAvailable) _away(StepsCard()),+ ],+ 'week': [if (fit.showWeekStats) ...[- const SizedBox(height: 30),_section(gc, t.thisWeek, null, _weekStats(context, gc)),],+ ],+ 'routines': [if (fit.showRoutineRow && routines.isNotEmpty) ...[- const SizedBox(height: 30),_section(gc, t.routines, fit.goRoutines, LayoutBuilder(builder: (context, box) => SizedBox(height: routineFolderHeight(context),@@ -83,7 +94,8 @@ class HomeScreen extends StatelessWidget {),)),],- const SizedBox(height: 30),+ ],+ 'activity': [_section(gc, t.activityLabel, fit.goProgress, SoftCard(radius: 22,borderColor: Colors.transparent,@@ -102,8 +114,9 @@ class HomeScreen extends StatelessWidget {onTapDay: (i) => showDaySheet(context, fit.heatmapWeekDate(i)),),)),+ ],+ 'recommended': [if (fit.showRecommended && recommended.isNotEmpty) ...[- const SizedBox(height: 30),_section(gc, t.recommended, fit.goExercises, SizedBox(height: 158,child: ListView.separated(@@ -114,7 +127,8 @@ class HomeScreen extends StatelessWidget {),)),],- const SizedBox(height: 30),+ ],+ 'folders': [_away(Row(crossAxisAlignment: CrossAxisAlignment.end,children: [@@ -146,8 +160,9 @@ class HomeScreen extends StatelessWidget {),],), dim: 0),+ ],+ 'nutrition': [if (fit.nutritionBeta) ...[- const SizedBox(height: 12),HomeFolder(title: _tc(t.nutrition),detail: _nutritionDetail,@@ -156,11 +171,26 @@ class HomeScreen extends StatelessWidget {onTap: fit.goNutrition,),],- ]),- ),- ),- ),- );+ ],+ };+ final out = <Widget>[];+ String? last;+ for (final id in fit.homeOrderShown) {+ final b = blocks[id];+ if (b == null || b.isEmpty) continue;+ final card = id == 'weekdays' || id == 'steps';+ final gap = last == null+ ? (fit.photoDue ? (card ? 14.0 : 30.0) : (card ? 0.0 : 16.0))+ : (card && (last == 'weekdays' || last == 'steps'))+ ? 14.0+ : id == 'nutrition' && last == 'folders'+ ? 12.0+ : 30.0;+ out.add(SizedBox(height: gap));+ out.addAll(b);+ last = id;+ }+ return out;}Widget _away(Widget child, {double dim = 0.45}) => ScrollAway(radius: 22, dim: dim, child: child);@@ -240,8 +270,8 @@ class HomeScreen extends StatelessWidget {height: 30,child: Row(children: [- Text(title.toUpperCase(),- style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.4)),+ Text(titleCase(title),+ style: AppTheme.f(13, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 0)),const Spacer(),if (onMore != null)Container(diff --git a/lib/services/home_widget_bridge.dart b/lib/services/home_widget_bridge.dartindex 4f3c77c..55618f5 100644--- a/lib/services/home_widget_bridge.dart+++ b/lib/services/home_widget_bridge.dart@@ -190,7 +190,7 @@ class HomeWidgetBridge {if (path != null) await HomeWidget.saveWidgetData<String>('${key}_night', path);}}- if (!_ios && NutritionWidgets.providers.any(wants)) {+ if (NutritionWidgets.providers.any(wants)) {await NutritionWidgets.paint(render: _render, wants: wants, day: day, night: night, framed: framed);}final now = DateTime.now();diff --git a/lib/services/nutrition_widgets.dart b/lib/services/nutrition_widgets.dartindex 9e6809f..ea6e288 100644--- a/lib/services/nutrition_widgets.dart+++ b/lib/services/nutrition_widgets.dart@@ -27,6 +27,7 @@ class NutritionWidgets {static const kcalSize = Size(320, 150);static const _pendingKey = 'nutri_pending';static const _route = MethodChannel('gymmane/open');+ static const _device = MethodChannel('gymmane/device');static String _signature = '';static String signature() {@@ -65,7 +66,7 @@ class NutritionWidgets {}static Future<void> takePending() async {- if (kIsWeb || !Platform.isAndroid) return;+ if (kIsWeb || !(Platform.isAndroid || Platform.isIOS)) return;try {final raw = await HomeWidget.getWidgetData<String>(_pendingKey);if (raw == null || raw.isEmpty) return;@@ -77,7 +78,7 @@ class NutritionWidgets {}static void listenOpen(void Function(String route) onOpen) {- if (kIsWeb || !Platform.isAndroid) return;+ if (kIsWeb || !(Platform.isAndroid || Platform.isIOS)) return;_route.setMethodCallHandler((call) async {final route = call.arguments;if (call.method == 'open' && route is String) onOpen(route);@@ -85,7 +86,7 @@ class NutritionWidgets {}static Future<String?> takeOpen() async {- if (kIsWeb || !Platform.isAndroid) return null;+ if (kIsWeb || !(Platform.isAndroid || Platform.isIOS)) return null;try {return await _route.invokeMethod<String>('take');} catch (_) {@@ -240,7 +241,7 @@ class NutritionWidgets {static Future<void> _frames(String prefix, VesselLook look) async {final key = '${look.asset}|${look.liquid.toARGB32()}|$levels|2';- final dir = Directory('${(await getApplicationSupportDirectory()).path}/widget_frames');+ final dir = await _framesDir();final last = File('${dir.path}/${prefix}_$levels.png');if (await HomeWidget.getWidgetData<String>('${prefix}_frames_key') == key && last.existsSync()) return;dir.createSync(recursive: true);@@ -276,6 +277,14 @@ class NutritionWidgets {await HomeWidget.saveWidgetData<String>('${prefix}_frames_key', key);}+ static Future<Directory> _framesDir() async {+ if (!kIsWeb && Platform.isIOS) {+ final group = await _device.invokeMethod<String>('groupDir');+ if (group != null) return Directory('$group/home_widget/frames');+ }+ return Directory('${(await getApplicationSupportDirectory()).path}/widget_frames');+ }+static Future<ui.Image> _load(String asset) async {final data = await rootBundle.load(asset);final codec = await ui.instantiateImageCodec(data.buffer.asUint8List());diff --git a/lib/widgets/home_cards_panel.dart b/lib/widgets/home_cards_panel.dartindex e96ca65..b409d72 100644--- a/lib/widgets/home_cards_panel.dart+++ b/lib/widgets/home_cards_panel.dart@@ -1,10 +1,12 @@import 'package:flutter/material.dart';import 'package:flutter/services.dart';+import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';import '../l10n/l10n.dart';import '../state/fit_state.dart';import '../theme/app_colors.dart';import '../theme/app_theme.dart';+import 'glass.dart';import 'ui_kit.dart';class HomeCardsPanel extends StatelessWidget {@@ -67,6 +69,29 @@ class HomeCardsPanel extends StatelessWidget {const SizedBox(width: 12),Expanded(flex: 8, child: SizedBox(height: rows.length * 54.0 - 8, child: _HomeSketch(gc: gc))),]),+ const SizedBox(height: 8),+ Pressable(+ scale: 0.97,+ onTap: () {+ HapticFeedback.selectionClick();+ _showOrderSheet(context);+ },+ child: Container(+ constraints: const BoxConstraints(minHeight: 46),+ padding: const EdgeInsetsDirectional.fromSTEB(14, 8, 12, 8),+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(16)),+ child: Row(children: [+ Expanded(+ child: Text(t.homeOrderRow,+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(13.5, weight: FontWeight.w700, color: gc.text)),+ ),+ const SizedBox(width: 6),+ Icon(PhosphorIconsRegular.arrowsDownUp, size: 17, color: gc.textSecondary),+ ]),+ ),+ ),]),),Padding(@@ -77,6 +102,75 @@ class HomeCardsPanel extends StatelessWidget {}}+String _blockLabel(String id) => switch (id) {+ 'weekdays' => t.homeOrderWeekdays,+ 'steps' => t.homeCardSteps,+ 'week' => t.homeCardWeek,+ 'routines' => t.homeCardRoutines,+ 'activity' => titleCase(t.activityLabel),+ 'recommended' => t.homeCardRecommended,+ 'folders' => t.homeOrderFolders,+ _ => titleCase(t.nutrition),+ };++void _showOrderSheet(BuildContext context) {+ final gc = context.gc;+ var order = [+ for (final id in fit.homeOrderShown)+ if ((id != 'nutrition' || fit.nutritionBeta) && (id != 'steps' || (fit.stepsOn && fit.stepsAvailable))) id,+ ];+ showAppSheet<void>(+ context: context,+ isScrollControlled: true,+ backgroundColor: Colors.transparent,+ builder: (sheet) => StatefulBuilder(+ builder: (sheet, setSheet) => AppSheet(children: [+ SheetTitle(t.homeOrderRow, subtitle: t.homeOrderHint),+ const SizedBox(height: 16),+ ReorderableListView(+ shrinkWrap: true,+ physics: const NeverScrollableScrollPhysics(),+ buildDefaultDragHandles: false,+ proxyDecorator: (child, _, _) => Material(color: Colors.transparent, child: child),+ onReorder: (from, to) {+ HapticFeedback.selectionClick();+ final next = [...order];+ next.insert(to > from ? to - 1 : to, next.removeAt(from));+ setSheet(() => order = next);+ fit.setHomeOrder([...next, for (final id in fit.homeOrderShown) if (!next.contains(id)) id]);+ },+ children: [+ for (final (i, id) in order.indexed)+ Container(+ key: ValueKey(id),+ margin: const EdgeInsets.only(bottom: 8),+ constraints: const BoxConstraints(minHeight: 52),+ padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 4, 8),+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(16)),+ child: Row(children: [+ Expanded(+ child: Text(_blockLabel(id),+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(14, weight: FontWeight.w700, color: gc.text)),+ ),+ ReorderableDragStartListener(+ index: i,+ child: SizedBox(+ width: 48,+ height: 44,+ child: Icon(PhosphorIconsRegular.dotsSixVertical, size: 18, color: gc.textTertiary),+ ),+ ),+ ]),+ ),+ ],+ ),+ ]),+ ),+ );+}+class _HomeSketch extends StatelessWidget {const _HomeSketch({required this.gc});@@ -126,19 +220,30 @@ class _HomeSketch extends StatelessWidget {),(fit.stepsOn && fit.stepsAvailable,- _box(18,- child: Center(- child: ClipRRect(- borderRadius: BorderRadius.circular(3),- child: SizedBox(- height: 4,- child: Row(children: [- Expanded(flex: 6, child: ColoredBox(color: gc.sage)),- Expanded(flex: 4, child: ColoredBox(color: gc.bgRaised2)),- ]),- ),+ _box(32,+ pad: const EdgeInsets.fromLTRB(9, 7, 9, 7),+ child: Row(crossAxisAlignment: CrossAxisAlignment.end, children: [+ Expanded(+ child: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [+ _bar(24, 6, gc.text.withValues(alpha: 0.75)),+ ClipRRect(+ borderRadius: BorderRadius.circular(3),+ child: SizedBox(+ height: 4,+ child: Row(children: [+ Expanded(flex: 6, child: ColoredBox(color: gc.text.withValues(alpha: 0.8))),+ Expanded(flex: 4, child: ColoredBox(color: gc.bgRaised2)),+ ]),+ ),+ ),+ ]),),- )),+ const SizedBox(width: 10),+ for (final h in const [8.0, 12.0, 10.0, 16.0, 6.0]) ...[+ _bar(3, h, gc.text.withValues(alpha: 0.7)),+ const SizedBox(width: 3),+ ],+ ])),),(fit.showWeekStats,@@ -200,6 +305,54 @@ class _HomeSketch extends StatelessWidget {]),),];+ final extra = <String, (bool, Widget)>{+ 'folders': (+ true,+ Row(children: [+ for (var i = 0; i < 3; i++) ...[+ if (i > 0) const SizedBox(width: 5),+ Expanded(child: _box(26, pad: const EdgeInsets.fromLTRB(5, 6, 5, 0), child: Align(+ alignment: Alignment.topCenter,+ child: _bar(double.infinity, 5, soft),+ ))),+ ],+ ]),+ ),+ 'nutrition': (+ fit.nutritionBeta,+ _box(32,+ pad: const EdgeInsets.fromLTRB(9, 7, 9, 7),+ child: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [+ _bar(30, 6, gc.text.withValues(alpha: 0.6)),+ ClipRRect(+ borderRadius: BorderRadius.circular(3),+ child: SizedBox(+ height: 4,+ child: Row(children: [+ Expanded(flex: 5, child: ColoredBox(color: gc.sage)),+ const SizedBox(width: 2),+ Expanded(flex: 3, child: ColoredBox(color: gc.accent)),+ const SizedBox(width: 2),+ Expanded(flex: 2, child: ColoredBox(color: gc.text.withValues(alpha: 0.35))),+ ]),+ ),+ ),+ ])),+ ),+ };+ final byId = <String, (bool, Widget)>{+ 'weekdays': blocks[1],+ 'steps': blocks[2],+ 'week': blocks[3],+ 'routines': blocks[4],+ 'activity': blocks[5],+ 'recommended': blocks[6],+ ...extra,+ };+ final shown = [+ blocks[0],+ for (final id in fit.homeOrderShown) ?byId[id],+ ];return ExcludeSemantics(child: ClipRRect(borderRadius: BorderRadius.circular(20),@@ -213,7 +366,7 @@ class _HomeSketch extends StatelessWidget {child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [Align(alignment: Alignment.centerLeft, child: _bar(40, 5, soft)),const SizedBox(height: 9),- for (final (on, child) in blocks)+ for (final (on, child) in shown)AnimatedSize(duration: const Duration(milliseconds: 320),curve: Curves.easeOutCubic,diff --git a/lib/widgets/nutrition_art.dart b/lib/widgets/nutrition_art.dartindex abd4a21..c4c8221 100644--- a/lib/widgets/nutrition_art.dart+++ b/lib/widgets/nutrition_art.dart@@ -927,10 +927,12 @@ class ValueLineChart extends StatelessWidget {this.fromZero = true,this.height = 168,this.tone,+ this.tags,});final List<double?> values;final List<String> labels;+ final List<String?>? tags;final String Function(double) format;final Color color;final double? goal;@@ -947,7 +949,7 @@ class ValueLineChart extends StatelessWidget {height: height,width: double.infinity,child: TweenAnimationBuilder<double>(- key: ValueKey(Object.hashAll([...values, goal])),+ key: ValueKey(Object.hashAll([...values, ...?tags, goal])),tween: Tween(begin: 0, end: 1),duration: const Duration(milliseconds: 900),curve: Curves.easeOutCubic,@@ -955,6 +957,7 @@ class ValueLineChart extends StatelessWidget {painter: _ValueLinePainter(values: values,labels: labels,+ tags: tags,format: format,color: color,goal: goal,@@ -975,6 +978,7 @@ class _ValueLinePainter extends CustomPainter {_ValueLinePainter({required this.values,required this.labels,+ required this.tags,required this.format,required this.color,required this.goal,@@ -988,6 +992,7 @@ class _ValueLinePainter extends CustomPainter {final List<double?> values;final List<String> labels;+ final List<String?>? tags;final String Function(double) format;final Color color;final double? goal;@@ -1107,7 +1112,7 @@ class _ValueLinePainter extends CustomPainter {..strokeWidth = hot ? 3 : 2.2,);final tag = _text(- format(values[i]!),+ (tags != null && i < tags!.length ? tags![i] : null) ?? format(values[i]!),AppTheme.f(hot ? 11.5 : 10.5, weight: FontWeight.w800, color: hot ? gc.text : gc.textSecondary),);final at = Offset(o.dx, o.dy - 15 - tag.height / 2);