Skip to content

Commit

Permalink
don't use future builder when not ensureScreenSize (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
mleevi committed Nov 1, 2023
1 parent 03a575f commit b780eb7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/src/screenutil_init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ScreenUtilInit extends StatefulWidget {
this.splitScreenMode = false,
this.minTextAdapt = false,
this.useInheritedMediaQuery = false,
this.ensureScreenSize,
this.ensureScreenSize = false,
this.responsiveWidgets,
this.fontSizeResolver = FontSizeResolvers.width,
}) : super(key: key);
Expand All @@ -83,7 +83,7 @@ class ScreenUtilInit extends StatefulWidget {
final bool splitScreenMode;
final bool minTextAdapt;
final bool useInheritedMediaQuery;
final bool? ensureScreenSize;
final bool ensureScreenSize;
final RebuildFactor rebuildFactor;
final FontSizeResolver fontSizeResolver;

Expand Down Expand Up @@ -133,7 +133,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
}

Future<void> _validateSize() async {
if (widget.ensureScreenSize ?? false) return ScreenUtil.ensureScreenSize();
if (widget.ensureScreenSize) return ScreenUtil.ensureScreenSize();
}

void _markNeedsBuildIfAllowed(Element el) {
Expand Down Expand Up @@ -171,6 +171,18 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>

if (mq == null) return const SizedBox.shrink();

if (!widget.ensureScreenSize) {
ScreenUtil.configure(
data: mq,
designSize: widget.designSize,
splitScreenMode: widget.splitScreenMode,
minTextAdapt: widget.minTextAdapt,
fontSizeResolver: widget.fontSizeResolver,
);

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

return FutureBuilder<void>(
future: _screenSizeCompleter.future,
builder: (c, snapshot) {
Expand Down

0 comments on commit b780eb7

Please sign in to comment.