Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Add share cards for the streak, the muscles and the before/after
InlitXb2582e3be894
diff --git a/lib/screens/share_sheet.dart b/lib/screens/share_sheet.dartnew file mode 100644index 0000000..c050463--- /dev/null+++ b/lib/screens/share_sheet.dart@@ -0,0 +1,159 @@+import 'dart:io';+import 'dart:ui' as ui;++import 'package:flutter/material.dart';+import 'package:flutter/rendering.dart';+import 'package:path_provider/path_provider.dart';+import 'package:share_plus/share_plus.dart';++import '../l10n/l10n.dart';+import '../state/fit_state.dart';+import '../theme/app_colors.dart';+import '../theme/app_theme.dart';+import '../widgets/share_cards.dart';+import '../widgets/ui_kit.dart';++Future<void> showShareSheet(BuildContext context, {ShareKind initial = ShareKind.streak}) =>+ showModalBottomSheet<void>(+ context: context,+ isScrollControlled: true,+ backgroundColor: Colors.transparent,+ builder: (_) => _ShareSheet(initial: initial),+ );++class _ShareSheet extends StatefulWidget {+ const _ShareSheet({required this.initial});++ final ShareKind initial;++ @override+ State<_ShareSheet> createState() => _ShareSheetState();+}++class _ShareSheetState extends State<_ShareSheet> {+ final GlobalKey _card = GlobalKey();+ late ShareKind _kind = widget.initial;+ bool _busy = false;++ List<ShareKind> get _available => [+ ShareKind.streak,+ ShareKind.body,+ if (fit.comparePair != null) ShareKind.compare,+ ];++ String _label(ShareKind k) => switch (k) {+ ShareKind.streak => t.shareStreak,+ ShareKind.body => t.shareBody,+ ShareKind.compare => t.shareCompare,+ };++ Future<void> _share() async {+ if (_busy) return;+ setState(() => _busy = true);+ try {+ final boundary = _card.currentContext?.findRenderObject() as RenderRepaintBoundary?;+ if (boundary == null) return;+ final image = await boundary.toImage(pixelRatio: 3);+ final data = await image.toByteData(format: ui.ImageByteFormat.png);+ image.dispose();+ if (data == null) return;++ final dir = await getTemporaryDirectory();+ final file = File('${dir.path}/gymmane-${_kind.name}.png');+ await file.writeAsBytes(data.buffer.asUint8List(), flush: true);+ if (!mounted) return;+ await SharePlus.instance.share(ShareParams(files: [XFile(file.path)], subject: 'GymMane'));+ } catch (_) {+ if (mounted) {+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(t.shareFailed)));+ }+ } finally {+ if (mounted) setState(() => _busy = false);+ }+ }++ @override+ Widget build(BuildContext context) {+ final gc = context.gc;+ final kinds = _available;+ final kind = kinds.contains(_kind) ? _kind : kinds.first;++ return Container(+ constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.9),+ decoration: BoxDecoration(+ color: gc.bg,+ border: Border.all(color: gc.border),+ borderRadius: const BorderRadius.vertical(top: Radius.circular(26)),+ ),+ clipBehavior: Clip.antiAlias,+ child: SafeArea(+ top: false,+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ Container(+ width: 40,+ height: 4,+ margin: const EdgeInsets.symmetric(vertical: 12),+ decoration: BoxDecoration(color: gc.border, borderRadius: BorderRadius.circular(2)),+ ),+ Padding(+ padding: const EdgeInsets.fromLTRB(20, 4, 20, 12),+ child: Row(+ children: [+ Expanded(+ child: Text(t.sharePick,+ style: AppTheme.d(17, weight: FontWeight.w700, color: gc.text)),+ ),+ ],+ ),+ ),+ SizedBox(+ height: 38,+ child: ListView(+ scrollDirection: Axis.horizontal,+ padding: const EdgeInsets.symmetric(horizontal: 20),+ children: [+ for (final k in kinds)+ Padding(+ padding: const EdgeInsets.only(right: 8),+ child: Pill(+ label: _label(k),+ bg: k == kind ? gc.emberSoft : gc.bgRaised,+ fg: k == kind ? gc.text : gc.textSecondary,+ fontSize: 12.5,+ onTap: () => setState(() => _kind = k),+ ),+ ),+ ],+ ),+ ),+ Flexible(+ child: SingleChildScrollView(+ padding: const EdgeInsets.fromLTRB(20, 18, 20, 8),+ child: Center(+ child: FittedBox(+ child: RepaintBoundary(+ key: _card,+ child: ShareCard(kind: kind, gc: gc),+ ),+ ),+ ),+ ),+ ),+ Padding(+ padding: const EdgeInsets.fromLTRB(20, 10, 20, 6),+ child: Text(t.shareHint,+ textAlign: TextAlign.center,+ style: AppTheme.s(11.5, color: gc.textTertiary, height: 1.4)),+ ),+ Padding(+ padding: const EdgeInsets.fromLTRB(20, 6, 20, 16),+ child: PrimaryButton(label: t.share, height: 54, onTap: _share),+ ),+ ],+ ),+ ),+ );+ }+}diff --git a/lib/widgets/share_cards.dart b/lib/widgets/share_cards.dartnew file mode 100644index 0000000..c6bfe79--- /dev/null+++ b/lib/widgets/share_cards.dart@@ -0,0 +1,227 @@+import 'dart:io';++import 'package:flutter/material.dart';++import '../l10n/l10n.dart';+import '../models/progress_shot.dart';+import '../services/media_store.dart';+import '../state/fit_state.dart';+import '../theme/app_colors.dart';+import '../theme/app_theme.dart';+import 'body_map.dart';+import 'charts.dart';++const Size kShareCardSize = Size(340, 425);++enum ShareKind { streak, body, compare }++class ShareCard extends StatelessWidget {+ const ShareCard({super.key, required this.kind, required this.gc});++ final ShareKind kind;+ final GymColors gc;++ @override+ Widget build(BuildContext context) {+ return SizedBox(+ width: kShareCardSize.width,+ height: kShareCardSize.height,+ child: DecoratedBox(+ decoration: BoxDecoration(+ gradient: LinearGradient(+ begin: Alignment.topLeft,+ end: Alignment.bottomRight,+ colors: [gc.bgRaised, gc.bg],+ ),+ border: Border.all(color: gc.border),+ borderRadius: BorderRadius.circular(28),+ ),+ child: Padding(+ padding: const EdgeInsets.fromLTRB(24, 22, 24, 20),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ Row(+ children: [+ Container(+ width: 8,+ height: 8,+ decoration: BoxDecoration(color: gc.accent, shape: BoxShape.circle),+ ),+ const SizedBox(width: 8),+ Text('GYMMANE',+ style: AppTheme.d(12,+ weight: FontWeight.w700, color: gc.text, letterSpacing: 4)),+ const Spacer(),+ Text(t.shortDateYear(DateTime.now()),+ style: AppTheme.s(11, color: gc.textTertiary)),+ ],+ ),+ const SizedBox(height: 20),+ Expanded(child: _body()),+ const SizedBox(height: 14),+ Container(height: 1, color: gc.border),+ const SizedBox(height: 10),+ Text(fit.profile.name.isEmpty ? 'GymMane' : fit.profile.name,+ style: AppTheme.s(11, weight: FontWeight.w600, color: gc.textTertiary)),+ ],+ ),+ ),+ ),+ );+ }++ Widget _body() => switch (kind) {+ ShareKind.streak => _streak(),+ ShareKind.body => _bodyMap(),+ ShareKind.compare => _compare(),+ };++ Widget _kicker(String text) => Text(text,+ style: AppTheme.d(11, weight: FontWeight.w600, color: gc.brass, letterSpacing: 3));++ Widget _stat(String label, String value, {String? unit, Color? color}) => Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(label,+ style: AppTheme.s(9.5, weight: FontWeight.w600, color: gc.textTertiary, letterSpacing: 1)),+ const SizedBox(height: 3),+ RichText(+ text: TextSpan(+ text: value,+ style: AppTheme.d(26, weight: FontWeight.w700, color: color ?? gc.text),+ children: [+ if (unit != null)+ TextSpan(+ text: ' $unit',+ style: AppTheme.d(12, weight: FontWeight.w700, color: gc.textSecondary)),+ ],+ ),+ ),+ ],+ );++ Widget _streak() {+ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ _kicker(t.consistency.toUpperCase()),+ const SizedBox(height: 8),+ Row(+ crossAxisAlignment: CrossAxisAlignment.end,+ children: [+ Text('${fit.currentStreak}',+ style: AppTheme.d(66, weight: FontWeight.w700, color: gc.text, height: 0.95)),+ const SizedBox(width: 8),+ Padding(+ padding: const EdgeInsets.only(bottom: 8),+ child: Text(t.shareStreakLabel.toLowerCase(),+ style: AppTheme.s(12, weight: FontWeight.w600, color: gc.textSecondary)),+ ),+ ],+ ),+ const SizedBox(height: 16),+ SizedBox(height: 122, child: Heatmap(levels: fit.heatmapLevelsFor(60))),+ const Spacer(),+ Row(+ children: [+ Expanded(child: _stat(t.shareSessionsLabel, '${fit.totalSessions}')),+ Expanded(+ child: _stat(t.shareVolumeLabel, fit.volumeValue(fit.volume30dKg),+ unit: fit.volumeUnit, color: gc.accent)),+ ],+ ),+ ],+ );+ }++ Widget _bodyMap() {+ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ _kicker(t.shareWeekOf),+ const SizedBox(height: 6),+ Text(t.shareBody,+ style: AppTheme.d(22, weight: FontWeight.w700, color: gc.text)),+ const SizedBox(height: 10),+ Expanded(+ child: Center(+ child: BodyHeatArt(gc: gc, intensity: fit.muscleHeatOver(7), width: 228),+ ),+ ),+ Row(+ children: [+ Expanded(child: _stat(t.shareSessionsLabel, '${fit.sessionsThisWeek}')),+ Expanded(+ child: _stat(t.shareStreakLabel, '${fit.currentStreak}', color: gc.accent)),+ ],+ ),+ ],+ );+ }++ Widget _compare() {+ final pair = fit.comparePair;+ if (pair == null) {+ return Center(child: Text(t.compareNeedTwo, style: AppTheme.s(13, color: gc.textSecondary)));+ }+ final pose = fit.posesWithBoth.contains(fit.comparePose)+ ? fit.comparePose+ : (fit.posesWithBoth.isEmpty ? null : fit.posesWithBoth.first);+ final delta = fit.compareWeightDelta;++ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ _kicker(t.daysApart(fit.compareDays).toUpperCase()),+ const SizedBox(height: 10),+ Expanded(+ child: Row(+ children: [+ Expanded(child: _shot(pair.from, pose)),+ const SizedBox(width: 10),+ Expanded(child: _shot(pair.to, pose)),+ ],+ ),+ ),+ const SizedBox(height: 12),+ Row(+ children: [+ Expanded(+ child: Text(t.shortDateYear(pair.from.date),+ style: AppTheme.s(11, weight: FontWeight.w600, color: gc.textTertiary)),+ ),+ const SizedBox(width: 10),+ Expanded(+ child: Text(t.shortDateYear(pair.to.date),+ textAlign: TextAlign.right,+ style: AppTheme.s(11, weight: FontWeight.w600, color: gc.textTertiary)),+ ),+ ],+ ),+ if (delta != null) ...[+ const SizedBox(height: 8),+ Text('${delta > 0 ? '+' : ''}${fmt(delta)} ${fit.units}',+ style: AppTheme.d(20, weight: FontWeight.w700, color: gc.accent)),+ ],+ ],+ );+ }++ Widget _shot(ProgressEntry entry, String? pose) {+ final name = pose == null ? (entry.media.isEmpty ? null : entry.media.first) : entry.shot(pose);+ final path = name == null ? null : MediaStore.pathFor(name);+ return Container(+ decoration: BoxDecoration(+ color: gc.bgRaised2,+ borderRadius: BorderRadius.circular(16),+ border: Border.all(color: gc.border),+ ),+ clipBehavior: Clip.antiAlias,+ child: path == null+ ? const SizedBox.expand()+ : Image.file(File(path), fit: BoxFit.cover, gaplessPlayback: true,+ errorBuilder: (_, _, _) => const SizedBox.expand()),+ );+ }+}