Skip to content

Commit

Permalink
Add fontSizeResolver to init + helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mounir Bouaiche committed Jun 11, 2023
1 parent fa79c78 commit 480205c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/src/screenutil_init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ abstract class RebuildFactors {
}
}

abstract class FontSizeResolvers {
static double width(num fontSize, ScreenUtil instance) {
return instance.setWidth(fontSize);
}

static double height(num fontSize, ScreenUtil instance) {
return instance.setHeight(fontSize);
}

static double raduis(num fontSize, ScreenUtil instance) {
return instance.radius(fontSize);
}

static double diameter(num fontSize, ScreenUtil instance) {
return instance.diameter(fontSize);
}

static double diagonal(num fontSize, ScreenUtil instance) {
return instance.diagonal(fontSize);
}
}

class ScreenUtilInit extends StatefulWidget {
/// A helper widget that initializes [ScreenUtil]
const ScreenUtilInit({
Expand All @@ -52,6 +74,7 @@ class ScreenUtilInit extends StatefulWidget {
this.useInheritedMediaQuery = false,
this.ensureScreenSize,
this.responsiveWidgets,
this.fontSizeResolver = FontSizeResolvers.width,
}) : super(key: key);

final ScreenUtilInitBuilder? builder;
Expand All @@ -61,6 +84,7 @@ class ScreenUtilInit extends StatefulWidget {
final bool useInheritedMediaQuery;
final bool? ensureScreenSize;
final RebuildFactor rebuildFactor;
final FontSizeResolver fontSizeResolver;

/// The [Size] of the device in the design draft, in dp
final Size designSize;
Expand Down Expand Up @@ -146,6 +170,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
splitScreenMode: widget.splitScreenMode,
minTextAdapt: widget.minTextAdapt,
ensureScreenHasSize: widget.ensureScreenSize,
fontSizeResolver: widget.fontSizeResolver,
);

return widget.builder?.call(context, widget.child) ?? widget.child!;
Expand Down

0 comments on commit 480205c

Please sign in to comment.