Skip to content

Commit

Permalink
[adaptive_style] changes from adaptive_mediaquery_widget to scale_med…
Browse files Browse the repository at this point in the history
…iaquery_widget
  • Loading branch information
Francesco Iapicca committed May 1, 2024
1 parent 7f9c579 commit 9390df6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
28 changes: 22 additions & 6 deletions packages/adaptive_style/lib/src/adaptive_mediaquery_widget.dart
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
);
}
9 changes: 6 additions & 3 deletions packages/adaptive_style/lib/src/scale_ref_provider.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -63,7 +66,7 @@ class _ScaleRefProvidertState extends State<ScaleRefProvider> {
valueListenable: _notifier,
builder: (context, scaleRef, _) => InheritedScaleRef(
scaleRef: scaleRef,
child: AdaptiveMediaQueryWidget(
child: ScaleMediaQueryWidget(
builder: widget.builder,
scale: _notifier.value.scale.min,
),
Expand Down

0 comments on commit 9390df6

Please sign in to comment.