Skip to content

Commit 0310503

Browse files
authored
feat!: Refactor Badge Control to a Dataclass; create new Control.badge property (#4077)
* Wrap control in _badge * Update create_control.dart * parseBadge function * Update badge_util.dart * Create badge_util.py * Update badge_util.py * String badge works * renamed budge to badge_old * renamed badge_util to badge * renamed Badge to BadgeOld * renamed Badgeutil to Badge * Update badge.dart * Update badge.py * Update badge.dart * offset * alignment * bgcolor * large_size * padding * small_size and label * text_color * text_style * cleanup * badge property for controls * added badge property to controls also fixed tooltip for Semantics * badge property for controls * badge to NavigationDestination, NavigationDrawerDestination, NavigationRailDestination * deleted old badge files * removed badge from NavigationDestination, NavigationBarDestination, NavigationRailDestination * Optional removed from BadgeValue
1 parent 8fa4706 commit 0310503

File tree

86 files changed

+512
-471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+512
-471
lines changed

client/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,10 +1354,10 @@ packages:
13541354
dependency: transitive
13551355
description:
13561356
name: vm_service
1357-
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
1357+
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
13581358
url: "https://pub.dev"
13591359
source: hosted
1360-
version: "14.2.4"
1360+
version: "14.2.5"
13611361
volume_controller:
13621362
dependency: transitive
13631363
description:

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

Lines changed: 0 additions & 70 deletions
This file was deleted.

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:math';
22

33
import 'package:collection/collection.dart';
4+
import 'package:flet/src/utils/badge.dart';
45
import 'package:flutter/material.dart';
56
import 'package:flutter_redux/flutter_redux.dart';
67

@@ -19,7 +20,6 @@ import 'alert_dialog.dart';
1920
import 'animated_switcher.dart';
2021
import 'auto_complete.dart';
2122
import 'autofill_group.dart';
22-
import 'badge.dart';
2323
import 'banner.dart';
2424
import 'barchart.dart';
2525
import 'bottom_app_bar.dart';
@@ -261,14 +261,6 @@ Widget createWidget(
261261
case "divider":
262262
return DividerControl(
263263
key: key, parent: parent, control: controlView.control);
264-
case "badge":
265-
return BadgeControl(
266-
key: key,
267-
parent: parent,
268-
control: controlView.control,
269-
children: controlView.children,
270-
parentDisabled: parentDisabled,
271-
parentAdaptive: parentAdaptive);
272264
case "selectionarea":
273265
return SelectionAreaControl(
274266
key: key,
@@ -1026,21 +1018,24 @@ Widget baseControl(
10261018
Widget constrainedControl(
10271019
BuildContext context, Widget widget, Control? parent, Control control) {
10281020
return _expandable(
1029-
_positionedControl(
1030-
context,
1031-
_aspectRatio(
1032-
_offsetControl(
1033-
context,
1034-
_scaledControl(
1021+
_badge(
1022+
_positionedControl(
1023+
context,
1024+
_aspectRatio(
1025+
_offsetControl(
10351026
context,
1036-
_rotatedControl(
1027+
_scaledControl(
10371028
context,
1038-
_sizedControl(
1039-
_directionality(
1040-
_tooltip(
1041-
_opacity(
1042-
context, widget, parent, control),
1043-
Theme.of(context),
1029+
_rotatedControl(
1030+
context,
1031+
_sizedControl(
1032+
_directionality(
1033+
_tooltip(
1034+
_opacity(
1035+
context, widget, parent, control),
1036+
Theme.of(context),
1037+
parent,
1038+
control),
10441039
parent,
10451040
control),
10461041
parent,
@@ -1055,6 +1050,7 @@ Widget constrainedControl(
10551050
control),
10561051
parent,
10571052
control),
1053+
Theme.of(context),
10581054
parent,
10591055
control),
10601056
parent,
@@ -1091,7 +1087,13 @@ Widget _opacity(
10911087
Widget _tooltip(
10921088
Widget widget, ThemeData theme, Control? parent, Control control) {
10931089
var tooltip = parseTooltip(control, "tooltip", widget, theme);
1094-
return tooltip != null ? tooltip : widget;
1090+
return tooltip ?? widget;
1091+
}
1092+
1093+
Widget _badge(
1094+
Widget widget, ThemeData theme, Control? parent, Control control) {
1095+
var badge = parseBadge(control, "badge", widget, theme);
1096+
return badge ?? widget;
10951097
}
10961098

10971099
Widget _aspectRatio(Widget widget, Control? parent, Control control) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'dart:convert';
2+
3+
import 'package:flet/flet.dart';
4+
import 'package:flutter/material.dart';
5+
6+
Badge? parseBadge(
7+
Control control, String propName, Widget widget, ThemeData theme) {
8+
var v = control.attrString(propName, null);
9+
if (v == null) {
10+
return null;
11+
}
12+
final j = json.decode(v);
13+
return badgeFromJSON(j, widget, theme);
14+
}
15+
16+
Badge? badgeFromJSON(dynamic j, Widget widget, ThemeData theme) {
17+
if (j == null) {
18+
return null;
19+
} else if (j is String) {
20+
return Badge(label: Text(j), child: widget);
21+
}
22+
23+
String? label = j["text"];
24+
25+
return Badge(
26+
label: label != null ? Text(label) : null,
27+
isLabelVisible: parseBool(j["label_visible"]) ?? true,
28+
offset: offsetFromJson(j["offset"]),
29+
alignment: alignmentFromJson(j["alignment"]),
30+
backgroundColor: parseColor(theme, j["bgcolor"]),
31+
largeSize: parseDouble(j["large_size"]),
32+
padding: edgeInsetsFromJson(j["padding"]),
33+
smallSize: parseDouble(j["small_size"]),
34+
textColor: parseColor(theme, j["text_color"]),
35+
textStyle: textStyleFromJson(theme, j["text_style"]),
36+
child: widget,
37+
);
38+
}

0 commit comments

Comments
 (0)