Skip to content

Commit a417cf3

Browse files
committed
Refactor: Introduce buildInControlContext and rename wrapper methods for clarity.
1 parent 3aba49e commit a417cf3

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

packages/flet/lib/src/controls/control_widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ControlWidget extends StatelessWidget {
3232
key = ValueKey(controlKey.value);
3333
}
3434

35-
return wrapWithControlInheritedNotifierAndTheme(control, (context) {
35+
return control.buildInControlContext((context) {
3636
for (var extension in FletBackend.of(context).extensions) {
3737
final widget = extension.createWidget(key, control);
3838
if (widget != null) return widget;

packages/flet/lib/src/controls/tabs.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class TabControl extends Tab {
245245
Widget build(BuildContext context) {
246246
debugPrint("TabControl build: ${control.id}");
247247

248-
return wrapWithControlInheritedNotifierAndTheme(control, (context) {
248+
return control.buildInControlContext((context) {
249249
return BaseControl(
250250
control: control,
251251
child: Tab(

packages/flet/lib/src/widgets/control_inherited_notifier.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ControlInheritedNotifier extends InheritedNotifier<Control> {
3535
///
3636
/// If `"skip_inherited_notifier"` internal is `true`, this returns
3737
/// [builder] unwrapped to preserve historical semantics.
38-
Widget withControlInheritedNotifier(Control control, WidgetBuilder builder) {
38+
Widget withControlNotifier(Control control, WidgetBuilder builder) {
3939
if (control.internals?["skip_inherited_notifier"] == true) {
4040
return Builder(builder: builder);
4141
}
@@ -50,15 +50,15 @@ Widget withControlInheritedNotifier(Control control, WidgetBuilder builder) {
5050
}
5151

5252
/// Convenience wrapper that applies both:
53-
/// - [withControlInheritedNotifier]
54-
/// - [wrapWithControlTheme]
55-
Widget wrapWithControlInheritedNotifierAndTheme(
53+
/// - [withControlNotifier]
54+
/// - [withControlTheme]
55+
Widget withControlContext(
5656
Control control,
5757
WidgetBuilder builder,
5858
) {
5959
return Builder(builder: (context) {
60-
final child = withControlInheritedNotifier(control, builder);
61-
return wrapWithControlTheme(control, context, child);
60+
final child = withControlNotifier(control, builder);
61+
return withControlTheme(control, context, child);
6262
});
6363
}
6464

@@ -73,8 +73,7 @@ Widget wrapWithControlInheritedNotifierAndTheme(
7373
/// - `control`: the control whose per-control theme (if any) will be applied.
7474
/// - `context`: used to access `FletBackend` and the ambient `Theme`.
7575
/// - `child`: the widget subtree to wrap with the per-control `Theme`.
76-
Widget wrapWithControlTheme(
77-
Control control, BuildContext context, Widget child) {
76+
Widget withControlTheme(Control control, BuildContext context, Widget child) {
7877
if (control == FletBackend.of(context).page) return child;
7978

8079
if (control.internals?["skip_inherited_notifier"] == true) return child;
@@ -114,3 +113,11 @@ Widget wrapWithControlTheme(
114113

115114
return buildTheme(themeModeToBrightness(themeMode));
116115
}
116+
117+
extension ControlContextBuilder on Control {
118+
/// Builds a widget under this control's standard "control context":
119+
/// [ControlInheritedNotifier] + per-control theme wrapping.
120+
Widget buildInControlContext(WidgetBuilder builder) {
121+
return withControlContext(this, builder);
122+
}
123+
}

0 commit comments

Comments
 (0)