Skip to content

Commit

Permalink
Flet 0.20.2 fixes (#2668)
Browse files Browse the repository at this point in the history
* `FletApp` control takes control create factories from a parent app

* Buttons turn to CupertinoDialogActionControl inside adaptive dialogs

* Page.adaptive should be passed to overlays

* Check minimal Flutter SDK version

* Flet version bumped to 0.20.2
  • Loading branch information
FeodorFitsner authored Feb 18, 2024
1 parent 8aa0f1b commit 17f4906
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 98 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Flet changelog

# 0.20.2
* Move `system_overlay_style` from `AppBar` to `Theme` ([#2667](https://github.com/flet-dev/flet/issues/2667)).
* `flet build` command checks minimal Flutter SDK version.
* Buttons turn to `CupertinoDialogAction` controls inside adaptive dialogs.
* `FletApp` control takes control create factories from a parent app.

# 0.20.1

* Migrated to Flutter 3.19
Expand Down
10 changes: 5 additions & 5 deletions client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -223,35 +223,35 @@ packages:
path: "../packages/flet"
relative: true
source: path
version: "0.20.1"
version: "0.20.2"
flet_audio:
dependency: "direct main"
description:
path: "../packages/flet_audio"
relative: true
source: path
version: "0.20.1"
version: "0.20.2"
flet_audio_recorder:
dependency: "direct main"
description:
path: "../packages/flet_audio_recorder"
relative: true
source: path
version: "0.20.1"
version: "0.20.2"
flet_video:
dependency: "direct main"
description:
path: "../packages/flet_video"
relative: true
source: path
version: "0.20.1"
version: "0.20.2"
flet_webview:
dependency: "direct main"
description:
path: "../packages/flet_webview"
relative: true
source: path
version: "0.20.1"
version: "0.20.2"
flutter:
dependency: "direct main"
description: flutter
Expand Down
6 changes: 6 additions & 0 deletions packages/flet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.20.2
* Move `system_overlay_style` from `AppBar` to `Theme` ([#2667](https://github.com/flet-dev/flet/issues/2667)).
* `flet build` command checks minimal Flutter SDK version.
* Buttons turn to `CupertinoDialogAction` controls inside adaptive dialogs.
* `FletApp` control takes control create factories from a parent app.

# 0.20.1

* Migrated to Flutter 3.19
Expand Down
1 change: 1 addition & 0 deletions packages/flet/lib/src/controls/create_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ Widget createWidget(
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled,
parentAdaptive: parentAdaptive,
backend: backend);
case "textbutton":
return TextButtonControl(
Expand Down
22 changes: 16 additions & 6 deletions packages/flet/lib/src/controls/elevated_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '../utils/icons.dart';
import '../utils/launch_url.dart';
import 'create_control.dart';
import 'cupertino_button.dart';
import 'cupertino_dialog_action.dart';
import 'error.dart';
import 'flet_store_mixin.dart';

Expand Down Expand Up @@ -66,12 +67,21 @@ class _ElevatedButtonControlState extends State<ElevatedButtonControl>
if (adaptive == true &&
(platform == TargetPlatform.iOS ||
platform == TargetPlatform.macOS)) {
return CupertinoButtonControl(
control: widget.control,
parentDisabled: widget.parentDisabled,
parentAdaptive: adaptive,
children: widget.children,
backend: widget.backend);
return widget.control.name == "action" &&
(widget.parent?.type == "alertdialog" ||
widget.parent?.type == "cupertinoalertdialog")
? CupertinoDialogActionControl(
control: widget.control,
parentDisabled: widget.parentDisabled,
parentAdaptive: adaptive,
children: widget.children,
backend: widget.backend)
: CupertinoButtonControl(
control: widget.control,
parentDisabled: widget.parentDisabled,
parentAdaptive: adaptive,
children: widget.children,
backend: widget.backend);
}

String text = widget.control.attrString("text", "")!;
Expand Down
3 changes: 3 additions & 0 deletions packages/flet/lib/src/controls/flet_app_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

import '../flet_app.dart';
import '../flet_app_errors_handler.dart';
import '../flet_app_services.dart';
import '../models/control.dart';
import 'create_control.dart';

Expand Down Expand Up @@ -36,6 +37,8 @@ class _FletAppControlState extends State<FletAppControl> {
pageUrl: url,
assetsDir: "",
errorsHandler: _errorsHandler,
createControlFactories:
FletAppServices.of(context).createControlFactories,
),
widget.parent,
widget.control);
Expand Down
146 changes: 88 additions & 58 deletions packages/flet/lib/src/controls/outlined_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import '../utils/colors.dart';
import '../utils/icons.dart';
import '../utils/launch_url.dart';
import 'create_control.dart';
import 'cupertino_button.dart';
import 'cupertino_dialog_action.dart';
import 'flet_store_mixin.dart';

class OutlinedButtonControl extends StatefulWidget {
final Control? parent;
final Control control;
final List<Control> children;
final bool parentDisabled;
final bool? parentAdaptive;
final FletControlBackend backend;

const OutlinedButtonControl(
Expand All @@ -21,13 +25,15 @@ class OutlinedButtonControl extends StatefulWidget {
required this.control,
required this.children,
required this.parentDisabled,
required this.parentAdaptive,
required this.backend});

@override
State<OutlinedButtonControl> createState() => _OutlinedButtonControlState();
}

class _OutlinedButtonControlState extends State<OutlinedButtonControl> {
class _OutlinedButtonControlState extends State<OutlinedButtonControl>
with FletStoreMixin {
late final FocusNode _focusNode;
String? _lastFocusValue;

Expand Down Expand Up @@ -92,62 +98,86 @@ class _OutlinedButtonControlState extends State<OutlinedButtonControl> {
}
: null;

OutlinedButton? button;

var theme = Theme.of(context);

var style = parseButtonStyle(Theme.of(context), widget.control, "style",
defaultForegroundColor: theme.colorScheme.primary,
defaultBackgroundColor: Colors.transparent,
defaultOverlayColor: Colors.transparent,
defaultShadowColor: Colors.transparent,
defaultSurfaceTintColor: Colors.transparent,
defaultElevation: 0,
defaultPadding: const EdgeInsets.all(8),
defaultBorderSide: BorderSide(color: theme.colorScheme.outline),
defaultShape: theme.useMaterial3
? const StadiumBorder()
: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)));

if (icon != null) {
button = OutlinedButton.icon(
autofocus: autofocus,
focusNode: _focusNode,
onPressed: onPressed,
onLongPress: onLongPressHandler,
style: style,
icon: Icon(
icon,
color: iconColor,
),
label: Text(text));
} else if (contentCtrls.isNotEmpty) {
button = OutlinedButton(
autofocus: autofocus,
focusNode: _focusNode,
onPressed: onPressed,
onLongPress: onLongPressHandler,
onHover: onHoverHandler,
style: style,
child:
createControl(widget.control, contentCtrls.first.id, disabled));
} else {
button = OutlinedButton(
autofocus: autofocus,
focusNode: _focusNode,
style: style,
onPressed: onPressed,
onLongPress: onLongPressHandler,
onHover: onHoverHandler,
child: Text(text));
}

var focusValue = widget.control.attrString("focus");
if (focusValue != null && focusValue != _lastFocusValue) {
_lastFocusValue = focusValue;
_focusNode.requestFocus();
}

return constrainedControl(context, button, widget.parent, widget.control);
return withPagePlatform((context, platform) {
bool? adaptive =
widget.control.attrBool("adaptive") ?? widget.parentAdaptive;
if (adaptive == true &&
(platform == TargetPlatform.iOS ||
platform == TargetPlatform.macOS)) {
return widget.control.name == "action" &&
(widget.parent?.type == "alertdialog" ||
widget.parent?.type == "cupertinoalertdialog")
? CupertinoDialogActionControl(
control: widget.control,
parentDisabled: widget.parentDisabled,
parentAdaptive: adaptive,
children: widget.children,
backend: widget.backend)
: CupertinoButtonControl(
control: widget.control,
parentDisabled: widget.parentDisabled,
parentAdaptive: adaptive,
children: widget.children,
backend: widget.backend);
}

OutlinedButton? button;

var theme = Theme.of(context);

var style = parseButtonStyle(Theme.of(context), widget.control, "style",
defaultForegroundColor: theme.colorScheme.primary,
defaultBackgroundColor: Colors.transparent,
defaultOverlayColor: Colors.transparent,
defaultShadowColor: Colors.transparent,
defaultSurfaceTintColor: Colors.transparent,
defaultElevation: 0,
defaultPadding: const EdgeInsets.all(8),
defaultBorderSide: BorderSide(color: theme.colorScheme.outline),
defaultShape: theme.useMaterial3
? const StadiumBorder()
: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)));

if (icon != null) {
button = OutlinedButton.icon(
autofocus: autofocus,
focusNode: _focusNode,
onPressed: onPressed,
onLongPress: onLongPressHandler,
style: style,
icon: Icon(
icon,
color: iconColor,
),
label: Text(text));
} else if (contentCtrls.isNotEmpty) {
button = OutlinedButton(
autofocus: autofocus,
focusNode: _focusNode,
onPressed: onPressed,
onLongPress: onLongPressHandler,
onHover: onHoverHandler,
style: style,
child:
createControl(widget.control, contentCtrls.first.id, disabled));
} else {
button = OutlinedButton(
autofocus: autofocus,
focusNode: _focusNode,
style: style,
onPressed: onPressed,
onLongPress: onLongPressHandler,
onHover: onHoverHandler,
child: Text(text));
}

var focusValue = widget.control.attrString("focus");
if (focusValue != null && focusValue != _lastFocusValue) {
_lastFocusValue = focusValue;
_focusNode.requestFocus();
}

return constrainedControl(context, button, widget.parent, widget.control);
});
}
}
8 changes: 6 additions & 2 deletions packages/flet/lib/src/controls/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ class _PageControlState extends State<PageControl> with FletStoreMixin {
"darkTheme", Brightness.dark)
: parseCupertinoTheme(
widget.control, "theme", Brightness.dark),
localizationsDelegates: const [
DefaultMaterialLocalizations.delegate
],
)
: MaterialApp.router(
debugShowCheckedModeBanner: false,
Expand Down Expand Up @@ -612,7 +615,8 @@ class _PageControlState extends State<PageControl> with FletStoreMixin {
overlayWidgets.addAll(routesView.offstageControls
.where((c) => !c.isNonVisual)
.map((c) => createControl(
routesView.page, c.id, routesView.page.isDisabled)));
routesView.page, c.id, routesView.page.isDisabled,
parentAdaptive: _adaptive)));
overlayWidgets.add(const PageMedia());
}

Expand Down Expand Up @@ -682,7 +686,7 @@ class _PageControlState extends State<PageControl> with FletStoreMixin {
in routesView.offstageControls.where((c) => c.isNonVisual)) {
nextChild = createControl(
routesView.page, c.id, routesView.page.isDisabled,
nextChild: nextChild);
parentAdaptive: _adaptive, nextChild: nextChild);
}

return nextChild;
Expand Down
22 changes: 16 additions & 6 deletions packages/flet/lib/src/controls/text_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '../utils/icons.dart';
import '../utils/launch_url.dart';
import 'create_control.dart';
import 'cupertino_button.dart';
import 'cupertino_dialog_action.dart';
import 'flet_store_mixin.dart';

class TextButtonControl extends StatefulWidget {
Expand Down Expand Up @@ -65,12 +66,21 @@ class _TextButtonControlState extends State<TextButtonControl>
if (adaptive == true &&
(platform == TargetPlatform.iOS ||
platform == TargetPlatform.macOS)) {
return CupertinoButtonControl(
control: widget.control,
parentDisabled: widget.parentDisabled,
parentAdaptive: adaptive,
children: widget.children,
backend: widget.backend);
return widget.control.name == "action" &&
(widget.parent?.type == "alertdialog" ||
widget.parent?.type == "cupertinoalertdialog")
? CupertinoDialogActionControl(
control: widget.control,
parentDisabled: widget.parentDisabled,
parentAdaptive: adaptive,
children: widget.children,
backend: widget.backend)
: CupertinoButtonControl(
control: widget.control,
parentDisabled: widget.parentDisabled,
parentAdaptive: adaptive,
children: widget.children,
backend: widget.backend);
}

String text = widget.control.attrString("text", "")!;
Expand Down
2 changes: 1 addition & 1 deletion packages/flet/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: flet
description: Write entire Flutter app in Python or add server-driven UI experience into existing Flutter app.
homepage: https://flet.dev
repository: https://github.com/flet-dev/flet/packages/flet
version: 0.20.1
version: 0.20.2

# This package supports all platforms listed below.
platforms:
Expand Down
4 changes: 4 additions & 0 deletions packages/flet_audio/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.20.2

No changes in this release. Version bumped to follow parent `flet` package.

## 0.20.1

No changes in this release. Version bumped to follow parent `flet` package.
Expand Down
2 changes: 1 addition & 1 deletion packages/flet_audio/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: flet_audio
description: Flet Audio control
homepage: https://flet.dev
repository: https://github.com/flet-dev/flet/packages/flet_audio
version: 0.20.1
version: 0.20.2

environment:
sdk: '>=3.2.3 <4.0.0'
Expand Down
Loading

0 comments on commit 17f4906

Please sign in to comment.