Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Add SheetPage and a softer background blur
InlitX4f6513e99902
diff --git a/lib/widgets/glass.dart b/lib/widgets/glass.dartindex 2536ee5..59e747e 100644--- a/lib/widgets/glass.dart+++ b/lib/widgets/glass.dart@@ -4,7 +4,9 @@ import 'package:flutter/material.dart';import '../theme/app_colors.dart';-const double kSheetBlur = 14;+bool blurEffects = true;++final sheetRecede = ValueNotifier<double>(0);final glassOpen = ValueNotifier<int>(0);final glassShown = ValueNotifier<int>(0);@@ -13,24 +15,22 @@ mixin _GlassCount<T> on ModalRoute<T> {static final _live = <_GlassCount>{};bool _open = false;- bool _handoff = false;- bool _handedOff = false;- bool get blurFull => _handoff;- bool get blurOff => _handedOff;+ static void _recede() {+ var v = 0.0;+ for (final r in _live) {+ final a = r.animation?.value ?? 0;+ if (a > v) v = a;+ }+ sheetRecede.value = Curves.easeOutCubic.transform(v.clamp(0.0, 1.0));+ }@overridevoid install() {super.install();- final closing = _live.where((r) => !r._open);- if (glassOpen.value == 0 && closing.isNotEmpty) {- _handoff = true;- for (final r in closing) {- r._handedOff = true;- }- }_open = true;_live.add(this);+ animation?.addListener(_recede);glassOpen.value++;glassShown.value++;}@@ -50,7 +50,9 @@ mixin _GlassCount<T> on ModalRoute<T> {@overridevoid dispose() {_close();+ animation?.removeListener(_recede);if (_live.remove(this)) glassShown.value--;+ _recede();super.dispose();}}@@ -74,7 +76,7 @@ Future<T?> showAppSheet<T>({isDismissible: isDismissible,enableDrag: enableDrag,useSafeArea: useSafeArea,- modalBarrierColor: Colors.black.withValues(alpha: 0.32),+ modalBarrierColor: Colors.black.withValues(alpha: 0.38),capturedThemes: InheritedTheme.capture(from: context, to: nav.context),barrierLabel: MaterialLocalizations.of(context).scrimLabel,));@@ -93,9 +95,6 @@ class _GlassSheetRoute<T> extends ModalBottomSheetRoute<T> with _GlassCount<T> {super.capturedThemes,super.barrierLabel,});-- @override- Widget buildModalBarrier() => _BlurBarrier(route: this, animation: animation!, child: super.buildModalBarrier());}class _PullToClose extends StatefulWidget {@@ -156,7 +155,7 @@ Future<T?> showAppDialog<T>({required BuildContext context, required WidgetBuildreturn nav.push(_GlassDialogRoute<T>(context: context,builder: builder,- barrierColor: Colors.black.withValues(alpha: 0.36),+ barrierColor: Colors.black.withValues(alpha: 0.4),themes: InheritedTheme.capture(from: context, to: nav.context),barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,));@@ -171,9 +170,6 @@ class _GlassDialogRoute<T> extends DialogRoute<T> with _GlassCount<T> {super.barrierLabel,});- @override- Widget buildModalBarrier() => _BlurBarrier(route: this, animation: animation!, child: super.buildModalBarrier());-@overrideWidget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondary, Widget child) {@@ -185,33 +181,6 @@ class _GlassDialogRoute<T> extends DialogRoute<T> with _GlassCount<T> {}}-class _BlurBarrier extends StatelessWidget {- const _BlurBarrier({required this.route, required this.animation, required this.child});-- final _GlassCount route;- final Animation<double> animation;- final Widget child;-- @override- Widget build(BuildContext context) {- return AnimatedBuilder(- animation: animation,- child: child,- builder: (context, barrier) {- if (route.blurOff) return barrier!;- final full = route.blurFull && animation.status != AnimationStatus.reverse;- final sigma = full- ? kSheetBlur- : kSheetBlur * Curves.easeOut.transform(animation.value.clamp(0.0, 1.0));- if (sigma < 0.3) return barrier!;- return BackdropFilter(- filter: ui.ImageFilter.blur(sigmaX: sigma, sigmaY: sigma),- child: barrier,- );- },- );- }-}class EdgeBlur extends StatefulWidget {const EdgeBlur({super.key, required this.height, this.top = true, this.sigma = 16, this.shade = 1});@@ -289,10 +258,12 @@ class _EdgeBlurState extends State<EdgeBlur> {height: widget.height,child: Stack(children: [- if (program != null)+ if (!blurEffects)+ const SizedBox.shrink()+ else if (program != null)for (final f in _layers(program, MediaQuery.devicePixelRatioOf(context)))Positioned.fill(- child: ClipRect(child: BackdropFilter.grouped(filter: f, child: const SizedBox.expand())),+ child: ClipRect(child: BackdropFilter(filter: f, child: const SizedBox.expand())),)else..._strips(),@@ -327,7 +298,7 @@ class _EdgeBlurState extends State<EdgeBlur> {top: widget.top ? strip * i : widget.height - strip * (i + 1),height: strip + 0.5,child: ClipRect(- child: BackdropFilter.grouped(+ child: BackdropFilter(filter: ui.ImageFilter.blur(sigmaX: widget.sigma * (1 - i / n) * 0.7,sigmaY: widget.sigma * (1 - i / n) * 0.7,@@ -364,11 +335,12 @@ class GlassSurface extends StatelessWidget {return ClipRRect(borderRadius: shape,child: BackdropFilter.grouped(+ enabled: blurEffects,filter: ui.ImageFilter.blur(sigmaX: blur, sigmaY: blur),child: DecoratedBox(decoration: BoxDecoration(borderRadius: shape,- color: tint ?? gc.bgRaised.withValues(alpha: dark ? 0.66 : 0.74),+ color: blurEffects ? tint ?? gc.bgRaised.withValues(alpha: dark ? 0.66 : 0.74) : gc.bgRaised,),child: DecoratedBox(decoration: BoxDecoration(diff --git a/lib/widgets/sheet_page.dart b/lib/widgets/sheet_page.dartnew file mode 100644index 0000000..427d3e2--- /dev/null+++ b/lib/widgets/sheet_page.dart@@ -0,0 +1,240 @@+import 'dart:math' as math;+import 'dart:ui' as ui;++import 'package:flutter/material.dart';++import '../state/fit_state.dart';+import '../theme/app_colors.dart';+import '../theme/app_theme.dart';+import 'svg_icon.dart';+import 'ui_kit.dart';++class SheetPage extends StatefulWidget {+ const SheetPage({+ super.key,+ required this.title,+ required this.onBack,+ required this.children,+ this.eyebrow,+ this.actions = const [],+ });++ final String title;+ final String? eyebrow;+ final List<Widget> actions;+ final VoidCallback onBack;+ final List<Widget> children;++ @override+ State<SheetPage> createState() => _SheetPageState();+}++class _SheetPageState extends State<SheetPage> {+ final _scroll = ScrollController();++ static const _side = 20.0;+ static const _corner = 32.0;+ static const _backTop = 12.0;+ static const _backSize = 40.0;++ @override+ void dispose() {+ _scroll.dispose();+ super.dispose();+ }++ double get _y => _scroll.hasClients ? _scroll.offset : 0.0;++ TextStyle _titleStyle(GymColors gc, double size) =>+ AppTheme.f(size, weight: FontWeight.w800, color: gc.text, letterSpacing: -size * 0.03, height: 1.0);++ (double, double) _fitTitle(GymColors gc, double maxWidth) {+ final words = widget.title.split(' ');+ TextPainter lay(double size) => TextPainter(+ text: TextSpan(text: widget.title, style: _titleStyle(gc, size)),+ textDirection: TextDirection.ltr,+ maxLines: 2,+ )..layout(maxWidth: maxWidth);+ var size = 42.0;+ while (size > 28) {+ final style = _titleStyle(gc, size);+ final widest = words+ .map((w) => (TextPainter(text: TextSpan(text: w, style: style), textDirection: TextDirection.ltr)..layout())+ .width)+ .fold(0.0, math.max);+ final all = lay(size);+ if (widest <= maxWidth && !all.didExceedMaxLines) return (size, all.height);+ size -= 2;+ }+ return (size, lay(size).height);+ }++ @override+ Widget build(BuildContext context) {+ final gc = context.gc;+ final pad = MediaQuery.paddingOf(context);+ final sheet = fit.dark ? Color.lerp(gc.bg, gc.bgRaised, 0.42)! : gc.bgRaised2;+ final eyebrow = widget.eyebrow;++ return LayoutBuilder(builder: (context, box) {+ final (size, titleH) = _fitTitle(gc, box.maxWidth - _side * 2);+ final bar = pad.top + _backTop + _backSize + 12;+ final titleTop = pad.top + _backTop + _backSize + (eyebrow == null ? 24 : 20);+ final header = titleTop + (eyebrow == null ? 0 : 24) + titleH + 34;+ final dockFrom = header - bar;++ return Stack(+ children: [+ Positioned(+ left: _side,+ right: _side,+ top: titleTop,+ child: IgnorePointer(+ child: AnimatedBuilder(+ animation: _scroll,+ builder: (context, child) {+ final p = (_y / header).clamp(0.0, 1.0);+ Widget layer = child!;+ if (p > 0.01 && fit.blurOn) {+ layer = ImageFiltered(+ imageFilter: ui.ImageFilter.blur(sigmaX: 6 * p, sigmaY: 6 * p),+ child: layer,+ );+ }+ return Transform.translate(+ offset: Offset(0, -_y * 0.45),+ child: Opacity(opacity: (1 - p * 1.4).clamp(0.0, 1.0), child: layer),+ );+ },+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ if (eyebrow != null) ...[+ Text(eyebrow.toUpperCase(),+ style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.4)),+ const SizedBox(height: 10),+ ],+ Text(widget.title, maxLines: 2, style: _titleStyle(gc, size)),+ ],+ ),+ ),+ ),+ ),+ SingleChildScrollView(+ controller: _scroll,+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ SizedBox(height: header),+ AnimatedBuilder(+ animation: _scroll,+ builder: (context, child) {+ final d = ((_y - dockFrom) / 18).clamp(0.0, 1.0);+ final r = Radius.circular(_corner * (1 - d));+ return ConstrainedBox(+ constraints: BoxConstraints(minHeight: box.maxHeight - bar),+ child: DecoratedBox(+ decoration: BoxDecoration(+ color: sheet,+ borderRadius: BorderRadius.vertical(top: r),+ border: Border.all(color: gc.text.withValues(alpha: 0.06 * (1 - d))),+ ),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ Opacity(+ opacity: 1 - d,+ child: SheetHandle(+ color: gc.text.withValues(alpha: 0.14),+ margin: const EdgeInsets.only(top: 10),+ ),+ ),+ child!,+ ],+ ),+ ),+ );+ },+ child: Padding(+ padding: EdgeInsets.fromLTRB(_side, 20, _side, pad.bottom + 40),+ child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: widget.children),+ ),+ ),+ ],+ ),+ ),+ Positioned(+ left: 0,+ right: 0,+ top: 0,+ height: bar + 24,+ child: AnimatedBuilder(+ animation: _scroll,+ builder: (context, _) {+ final d = ((_y - dockFrom + 6) / 24).clamp(0.0, 1.0);+ return Stack(+ children: [+ Positioned.fill(+ child: IgnorePointer(+ child: Opacity(+ opacity: d,+ child: DecoratedBox(+ decoration: BoxDecoration(+ gradient: LinearGradient(+ begin: Alignment.topCenter,+ end: Alignment.bottomCenter,+ stops: [0, bar / (bar + 24), 1],+ colors: [sheet, sheet, sheet.withValues(alpha: 0)],+ ),+ ),+ ),+ ),+ ),+ ),+ Positioned(+ left: _side,+ top: pad.top + _backTop,+ child: RoundBtn(icon: Ic.chevronLeft, onTap: widget.onBack),+ ),+ Positioned(+ left: _side + _backSize + 14,+ right: _side + widget.actions.length * 44,+ top: pad.top + _backTop,+ height: _backSize,+ child: IgnorePointer(+ child: Opacity(+ opacity: d,+ child: Transform.translate(+ offset: Offset(0, 8 * (1 - d)),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text(widget.title,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(17, weight: FontWeight.w800, color: gc.text, letterSpacing: -0.3)),+ ),+ ),+ ),+ ),+ ),+ if (widget.actions.isNotEmpty)+ Positioned(+ right: _side,+ top: pad.top + _backTop + 2,+ child: Row(children: [+ for (var i = 0; i < widget.actions.length; i++) ...[+ if (i > 0) const SizedBox(width: 8),+ widget.actions[i],+ ],+ ]),+ ),+ ],+ );+ },+ ),+ ),+ ],+ );+ });+ }+}