diff --git a/packages/adaptive_style/lib/src/adaptive_mediaquery_widget.dart b/packages/adaptive_style/lib/src/adaptive_mediaquery_widget.dart index 1b1b56d2..8ffcd432 100644 --- a/packages/adaptive_style/lib/src/adaptive_mediaquery_widget.dart +++ b/packages/adaptive_style/lib/src/adaptive_mediaquery_widget.dart @@ -1,14 +1,30 @@ import 'package:flutter/widgets.dart'; import 'package:yak_flutter/yak_flutter.dart'; -class AdaptiveMediaQueryWidget extends MediaQueryWidget { +typedef ScaleMediaQuery = MediaQueryData Function( + MediaQueryData mediaQuery, + double scale, +); + +MediaQueryData _defaultScaleMediaQuery( + MediaQueryData mediaQuery, + double scale, +) => + mediaQuery.copyWith( + textScaler: TextScaler.linear(scale), + ); + +class ScaleMediaQueryWidget extends MediaQueryWidget { final double scale; final WidgetBuilder builder; - const AdaptiveMediaQueryWidget({ + final ScaleMediaQuery scaleMediaQuery; + + const ScaleMediaQueryWidget({ required this.builder, required this.scale, + ScaleMediaQuery? scaleMediaQuery, super.key, - }); + }) : scaleMediaQuery = scaleMediaQuery ?? _defaultScaleMediaQuery; @override Widget build(context) => key == null @@ -19,8 +35,8 @@ class AdaptiveMediaQueryWidget extends MediaQueryWidget { ); @override - MediaQueryData mediaQueryFrom(MediaQueryData mediaQuery) => - mediaQuery.copyWith( - textScaler: TextScaler.linear(scale), + MediaQueryData mediaQueryFrom(MediaQueryData mediaQuery) => scaleMediaQuery( + mediaQuery, + scale, ); } diff --git a/packages/adaptive_style/lib/src/scale_ref_provider.dart b/packages/adaptive_style/lib/src/scale_ref_provider.dart index e697f1ab..15d06985 100644 --- a/packages/adaptive_style/lib/src/scale_ref_provider.dart +++ b/packages/adaptive_style/lib/src/scale_ref_provider.dart @@ -1,9 +1,12 @@ import 'dart:async'; -import 'package:adaptive_style/adaptive_style.dart'; import 'package:flutter/widgets.dart'; - +import 'adaptive_mediaquery_widget.dart'; +import 'device_size.dart'; import 'inherited_scale_ref.dart'; +import 'scale_ref.dart'; +import 'extension.dart'; +import 'size_scale.dart'; class ScaleRefProvider extends StatefulWidget { final WidgetBuilder builder; @@ -63,7 +66,7 @@ class _ScaleRefProvidertState extends State { valueListenable: _notifier, builder: (context, scaleRef, _) => InheritedScaleRef( scaleRef: scaleRef, - child: AdaptiveMediaQueryWidget( + child: ScaleMediaQueryWidget( builder: widget.builder, scale: _notifier.value.scale.min, ),