Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use FutureBuilder when not ensureScreenSize #517

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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