Skip to content

Commit

Permalink
Update logic if allowing widget to being rebuilt
Browse files Browse the repository at this point in the history
  • Loading branch information
Mounir Bouaiche committed Jun 11, 2023
1 parent c09793d commit 6fed40a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/src/screenutil_init.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'dart:collection';

import 'package:flutter/widgets.dart';
import './_flutter_widgets.dart';

import 'screenutil_mixin.dart';
import 'screen_util.dart';
Expand Down Expand Up @@ -67,13 +70,16 @@ class ScreenUtilInit extends StatefulWidget {

class _ScreenUtilInitState extends State<ScreenUtilInit>
with WidgetsBindingObserver {
late final Iterable<String>? _canMarkedToBuild;
final _canMarkedToBuild = HashSet<String>();
MediaQueryData? _mediaQueryData;
final WidgetsBinding _binding = WidgetsBinding.instance;
final _binding = WidgetsBinding.instance;

@override
void initState() {
_canMarkedToBuild = widget.responsiveWidgets;
if (widget.responsiveWidgets != null) {
_canMarkedToBuild.addAll(widget.responsiveWidgets!);
}

super.initState();
_binding.addObserver(this);
}
Expand All @@ -98,13 +104,12 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
}

void _markNeedsBuildIfAllowed(Element el) {
if (_canMarkedToBuild != null) {
final widget = el.widget, widgetName = el.widget.runtimeType.toString();

if (widget is! SU && !_canMarkedToBuild!.contains(widgetName)) return;
}
final widgetName = el.widget.runtimeType.toString();
final allowed = widget is SU ||
_canMarkedToBuild.contains(widgetName) ||
!(widgetName.startsWith('_') || flutterWidgets.contains(widgetName));

el.markNeedsBuild();
if (allowed) el.markNeedsBuild();
}

void _updateTree(Element el) {
Expand Down

0 comments on commit 6fed40a

Please sign in to comment.