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

feat!: Refactor Badge Control to a Dataclass; create new Control.badge property #4077

Merged
merged 31 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cae8094
Wrap control in _badge
InesaFitsner Sep 26, 2024
8a61e49
Update create_control.dart
InesaFitsner Sep 26, 2024
f1452c9
parseBadge function
InesaFitsner Sep 26, 2024
8d5b9a2
Update badge_util.dart
InesaFitsner Sep 26, 2024
2b06a1b
Create badge_util.py
InesaFitsner Sep 26, 2024
5434c86
Update badge_util.py
InesaFitsner Sep 26, 2024
6cc3a71
String badge works
InesaFitsner Sep 26, 2024
3ffa687
renamed budge to badge_old
InesaFitsner Sep 27, 2024
9db0096
renamed badge_util to badge
InesaFitsner Sep 27, 2024
58e1a91
renamed Badge to BadgeOld
InesaFitsner Sep 27, 2024
4512047
renamed Badgeutil to Badge
InesaFitsner Sep 27, 2024
cd20e4a
Update badge.dart
InesaFitsner Sep 27, 2024
71b023f
Update badge.py
InesaFitsner Sep 27, 2024
20b4ae8
Update badge.dart
InesaFitsner Sep 27, 2024
cc20f1f
offset
InesaFitsner Sep 27, 2024
9ca8726
alignment
InesaFitsner Sep 27, 2024
37dd226
bgcolor
InesaFitsner Sep 27, 2024
42a6374
large_size
InesaFitsner Sep 27, 2024
279b38c
padding
InesaFitsner Sep 27, 2024
36803f3
small_size and label
InesaFitsner Sep 27, 2024
81fac2a
text_color
InesaFitsner Sep 27, 2024
7d6d281
text_style
InesaFitsner Sep 27, 2024
9c16d26
cleanup
InesaFitsner Sep 27, 2024
75f0f4c
badge property for controls
InesaFitsner Sep 27, 2024
369dae7
added badge property to controls
InesaFitsner Sep 27, 2024
d4772b1
badge property for controls
InesaFitsner Sep 27, 2024
bd2d47b
badge to NavigationDestination, NavigationDrawerDestination, Navigati…
InesaFitsner Sep 27, 2024
f51a10c
deleted old badge files
InesaFitsner Oct 1, 2024
742562d
removed badge from NavigationDestination, NavigationBarDestination, N…
InesaFitsner Oct 1, 2024
3dfb02e
Merge branch 'main' into badge-property
InesaFitsner Oct 29, 2024
236144f
Optional removed from BadgeValue
InesaFitsner Oct 29, 2024
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
70 changes: 0 additions & 70 deletions packages/flet/lib/src/controls/badge.dart

This file was deleted.

48 changes: 25 additions & 23 deletions packages/flet/lib/src/controls/create_control.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';

import 'package:collection/collection.dart';
import 'package:flet/src/utils/badge.dart';
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';

Expand All @@ -19,7 +20,6 @@ import 'alert_dialog.dart';
import 'animated_switcher.dart';
import 'auto_complete.dart';
import 'autofill_group.dart';
import 'badge.dart';
import 'banner.dart';
import 'barchart.dart';
import 'bottom_app_bar.dart';
Expand Down Expand Up @@ -261,14 +261,6 @@ Widget createWidget(
case "divider":
return DividerControl(
key: key, parent: parent, control: controlView.control);
case "badge":
return BadgeControl(
key: key,
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled,
parentAdaptive: parentAdaptive);
case "selectionarea":
return SelectionAreaControl(
key: key,
Expand Down Expand Up @@ -1024,21 +1016,24 @@ Widget baseControl(
Widget constrainedControl(
BuildContext context, Widget widget, Control? parent, Control control) {
return _expandable(
_positionedControl(
context,
_aspectRatio(
_offsetControl(
context,
_scaledControl(
_badge(
_positionedControl(
context,
_aspectRatio(
_offsetControl(
context,
_rotatedControl(
_scaledControl(
context,
_sizedControl(
_directionality(
_tooltip(
_opacity(
context, widget, parent, control),
Theme.of(context),
_rotatedControl(
context,
_sizedControl(
_directionality(
_tooltip(
_opacity(
context, widget, parent, control),
Theme.of(context),
parent,
control),
parent,
control),
parent,
Expand All @@ -1053,6 +1048,7 @@ Widget constrainedControl(
control),
parent,
control),
Theme.of(context),
parent,
control),
parent,
Expand Down Expand Up @@ -1089,7 +1085,13 @@ Widget _opacity(
Widget _tooltip(
Widget widget, ThemeData theme, Control? parent, Control control) {
var tooltip = parseTooltip(control, "tooltip", widget, theme);
return tooltip != null ? tooltip : widget;
return tooltip ?? widget;
}

Widget _badge(
Widget widget, ThemeData theme, Control? parent, Control control) {
var badge = parseBadge(control, "badge", widget, theme);
return badge ?? widget;
}

Widget _aspectRatio(Widget widget, Control? parent, Control control) {
Expand Down
38 changes: 38 additions & 0 deletions packages/flet/lib/src/utils/badge.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dart:convert';

import 'package:flet/flet.dart';
import 'package:flutter/material.dart';

Badge? parseBadge(
Control control, String propName, Widget widget, ThemeData theme) {
var v = control.attrString(propName, null);
if (v == null) {
return null;
}
final j = json.decode(v);
return badgeFromJSON(j, widget, theme);
}

Badge? badgeFromJSON(dynamic j, Widget widget, ThemeData theme) {
if (j == null) {
return null;
} else if (j is String) {
return Badge(label: Text(j), child: widget);
}

String? label = j["text"];

return Badge(
label: label != null ? Text(label) : null,
isLabelVisible: parseBool(j["label_visible"]) ?? true,
offset: offsetFromJson(j["offset"]),
alignment: alignmentFromJson(j["alignment"]),
backgroundColor: parseColor(theme, j["bgcolor"]),
largeSize: parseDouble(j["large_size"]),
padding: edgeInsetsFromJson(j["padding"]),
smallSize: parseDouble(j["small_size"]),
textColor: parseColor(theme, j["text_color"]),
textStyle: textStyleFromJson(theme, j["text_style"]),
child: widget,
);
}
Loading