Skip to content

Commit 35d52be

Browse files
update the samples for new feature.
1 parent b63b4e9 commit 35d52be

File tree

21 files changed

+456
-1255
lines changed

21 files changed

+456
-1255
lines changed

images/code.png

-1.48 KB
Binary file not shown.

images/treemap_ascending_dark.png

438 Bytes
Loading

images/treemap_ascending_light.png

432 Bytes
Loading

images/treemap_descending_dark.png

520 Bytes
Loading

images/treemap_descending_light.png

521 Bytes
Loading

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Future<void> main() async {
66
WidgetsFlutterBinding.ensureInitialized();
77
await updateControlItems();
88
runApp(const SampleBrowser());
9-
}
9+
}

lib/samples/chart/cartesian_charts/legend/legend_various_options.dart

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ class _CartesianLegendOptionsState extends SampleViewState {
2323
_CartesianLegendOptionsState();
2424

2525
late bool toggleVisibility;
26+
late bool enableFloatingLegend;
2627
final List<String> _positionList =
2728
<String>['auto', 'bottom', 'left', 'right', 'top'].toList();
2829
late String _selectedPosition;
2930
late LegendPosition _position;
3031
final List<String> _modeList = <String>['wrap', 'scroll', 'none'].toList();
3132
late String _selectedMode;
3233
late LegendItemOverflowMode _overflowMode;
33-
late double _xOffset = double.nan;
34-
late double _yOffset = double.nan;
34+
late double _xOffset = 0.0;
35+
late double _yOffset = 0.0;
3536

3637
@override
3738
void initState() {
@@ -40,6 +41,7 @@ class _CartesianLegendOptionsState extends SampleViewState {
4041
_selectedMode = 'wrap';
4142
_overflowMode = LegendItemOverflowMode.wrap;
4243
toggleVisibility = true;
44+
enableFloatingLegend = false;
4345
super.initState();
4446
}
4547

@@ -133,6 +135,28 @@ class _CartesianLegendOptionsState extends SampleViewState {
133135
});
134136
})),
135137
),
138+
ListTile(
139+
title: Text(
140+
model.isWebFullView ? 'Floating \nlegend' : 'Floating legend',
141+
softWrap: false,
142+
style: TextStyle(
143+
color: model.textColor,
144+
)),
145+
trailing: Container(
146+
padding: EdgeInsets.only(left: 0.05 * screenWidth),
147+
width: 0.4 * screenWidth,
148+
child: CheckboxListTile(
149+
controlAffinity: ListTileControlAffinity.leading,
150+
contentPadding: EdgeInsets.zero,
151+
activeColor: model.backgroundColor,
152+
value: enableFloatingLegend,
153+
onChanged: (bool? value) {
154+
setState(() {
155+
enableFloatingLegend = value!;
156+
stateSetter(() {});
157+
});
158+
})),
159+
),
136160
ListTile(
137161
title: Text('X offset',
138162
style: TextStyle(
@@ -145,13 +169,16 @@ class _CartesianLegendOptionsState extends SampleViewState {
145169
minValue: -100,
146170
maxValue: 100,
147171
initialValue: _xOffset,
148-
needNull: true,
149172
onChanged: (double val) => setState(() {
150-
_xOffset = val;
173+
_xOffset = enableFloatingLegend ? val : 0;
151174
}),
152-
step: 10,
153-
iconColor: model.textColor,
154-
style: TextStyle(fontSize: 16.0, color: model.textColor),
175+
step: enableFloatingLegend ? 10 : 0,
176+
iconColor: model.textColor
177+
.withOpacity(enableFloatingLegend ? 1 : 0.5),
178+
style: TextStyle(
179+
fontSize: 16.0,
180+
color: model.textColor
181+
.withOpacity(enableFloatingLegend ? 1 : 0.5)),
155182
),
156183
)),
157184
ListTile(
@@ -165,14 +192,17 @@ class _CartesianLegendOptionsState extends SampleViewState {
165192
child: CustomDirectionalButtons(
166193
minValue: -100,
167194
maxValue: 100,
168-
needNull: true,
169195
initialValue: _yOffset,
170196
onChanged: (double val) => setState(() {
171-
_yOffset = val;
197+
_yOffset = enableFloatingLegend ? val : 0;
172198
}),
173-
step: 10,
174-
iconColor: model.textColor,
175-
style: TextStyle(fontSize: 16.0, color: model.textColor),
199+
step: enableFloatingLegend ? 10 : 0,
200+
iconColor: model.textColor
201+
.withOpacity(enableFloatingLegend ? 1 : 0.5),
202+
style: TextStyle(
203+
fontSize: 16.0,
204+
color: model.textColor
205+
.withOpacity(enableFloatingLegend ? 1 : 0.5)),
176206
),
177207
)),
178208
],
@@ -191,9 +221,7 @@ class _CartesianLegendOptionsState extends SampleViewState {
191221
legend: Legend(
192222
isVisible: true,
193223
position: _position,
194-
offset: (_xOffset.isNaN || _yOffset.isNaN)
195-
? null
196-
: Offset(_xOffset, _yOffset),
224+
offset: enableFloatingLegend ? Offset(_xOffset, _yOffset) : null,
197225
overflowMode: _overflowMode,
198226
toggleSeriesVisibility: toggleVisibility,
199227
backgroundColor: model.currentThemeData?.brightness == Brightness.light

lib/samples/chart/circular_charts/legend/legend_with_various_options.dart

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class LegendOptions extends SampleView {
2020
class _LegendOptionsState extends SampleViewState {
2121
_LegendOptionsState();
2222
bool toggleVisibility = true;
23+
bool enableFloatingLegend = false;
2324
final List<String> _positionList =
2425
<String>['auto', 'bottom', 'left', 'right', 'top'].toList();
2526
String _selectedPosition = 'auto';
@@ -28,8 +29,8 @@ class _LegendOptionsState extends SampleViewState {
2829
final List<String> _modeList = <String>['wrap', 'scroll', 'none'].toList();
2930
String _selectedMode = 'wrap';
3031
LegendItemOverflowMode _overflowMode = LegendItemOverflowMode.wrap;
31-
late double _xOffset = double.nan;
32-
late double _yOffset = double.nan;
32+
late double _xOffset = 0.0;
33+
late double _yOffset = 0.0;
3334

3435
@override
3536
Widget buildSettings(BuildContext context) {
@@ -118,6 +119,28 @@ class _LegendOptionsState extends SampleViewState {
118119
});
119120
})),
120121
),
122+
ListTile(
123+
title: Text(
124+
model.isWebFullView ? 'Floating \nlegend' : 'Floating legend',
125+
softWrap: false,
126+
style: TextStyle(
127+
color: model.textColor,
128+
)),
129+
trailing: Container(
130+
padding: EdgeInsets.only(left: 0.05 * screenWidth),
131+
width: 0.4 * screenWidth,
132+
child: CheckboxListTile(
133+
controlAffinity: ListTileControlAffinity.leading,
134+
contentPadding: EdgeInsets.zero,
135+
activeColor: model.backgroundColor,
136+
value: enableFloatingLegend,
137+
onChanged: (bool? value) {
138+
setState(() {
139+
enableFloatingLegend = value!;
140+
stateSetter(() {});
141+
});
142+
})),
143+
),
121144
ListTile(
122145
title: Text('X offset',
123146
style: TextStyle(
@@ -129,14 +152,17 @@ class _LegendOptionsState extends SampleViewState {
129152
child: CustomDirectionalButtons(
130153
minValue: -100,
131154
maxValue: 100,
132-
needNull: true,
133155
initialValue: _xOffset,
134156
onChanged: (double val) => setState(() {
135-
_xOffset = val;
157+
_xOffset = enableFloatingLegend ? val : 0;
136158
}),
137-
step: 10,
138-
iconColor: model.textColor,
139-
style: TextStyle(fontSize: 16.0, color: model.textColor),
159+
step: enableFloatingLegend ? 10 : 0,
160+
iconColor: model.textColor
161+
.withOpacity(enableFloatingLegend ? 1 : 0.5),
162+
style: TextStyle(
163+
fontSize: 16.0,
164+
color: model.textColor
165+
.withOpacity(enableFloatingLegend ? 1 : 0.5)),
140166
),
141167
)),
142168
ListTile(
@@ -150,14 +176,17 @@ class _LegendOptionsState extends SampleViewState {
150176
child: CustomDirectionalButtons(
151177
minValue: -100,
152178
maxValue: 100,
153-
needNull: true,
154179
initialValue: _yOffset,
155180
onChanged: (double val) => setState(() {
156-
_yOffset = val;
181+
_yOffset = enableFloatingLegend ? val : 0;
157182
}),
158-
step: 10,
159-
iconColor: model.textColor,
160-
style: TextStyle(fontSize: 16.0, color: model.textColor),
183+
step: enableFloatingLegend ? 10 : 0,
184+
iconColor: model.textColor
185+
.withOpacity(enableFloatingLegend ? 1 : 0.5),
186+
style: TextStyle(
187+
fontSize: 16.0,
188+
color: model.textColor
189+
.withOpacity(enableFloatingLegend ? 1 : 0.5)),
161190
),
162191
)),
163192
],
@@ -177,9 +206,7 @@ class _LegendOptionsState extends SampleViewState {
177206
legend: Legend(
178207
isVisible: true,
179208
position: _position,
180-
offset: (_xOffset.isNaN || _yOffset.isNaN)
181-
? null
182-
: Offset(_xOffset, _yOffset),
209+
offset: enableFloatingLegend ? Offset(_xOffset, _yOffset) : null,
183210
overflowMode: _overflowMode,
184211
toggleSeriesVisibility: toggleVisibility),
185212
series: _getLegendOptionsSeries(),

lib/samples/maps/shape_layer/legend/legend.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,9 @@ class _MapLegendPageState extends SampleViewState {
381381
),
382382
child: Column(children: <Widget>[
383383
Padding(
384-
padding: const EdgeInsets.only(top: 15, bottom: 30),
384+
padding: EdgeInsets.only(
385+
top: 15,
386+
bottom: (_enableGradient && !model.isMobile) ? 18 : 30),
385387
child: Align(
386388
alignment: Alignment.center,
387389
child: Text('Average Internet Prices in Africa',
@@ -492,13 +494,10 @@ class _MapLegendPageState extends SampleViewState {
492494
? MapLegendPaintingStyle.gradient
493495
: MapLegendPaintingStyle.solid,
494496
segmentSize: _enableGradient
495-
? const Size(300.0, 9.0)
497+
? const Size(279.0, 9.0)
496498
: const Size(55.0, 9.0),
497499
showPointerOnHover: true,
498-
padding: EdgeInsets.only(
499-
bottom: (_enableGradient && !model.isMobile)
500-
? 30
501-
: 20),
500+
padding: const EdgeInsets.only(bottom: 20),
502501
)
503502
: MapLegend(
504503
/// You can show legend for the shapes or bubbles. By

lib/samples/sliders/range_slider/customization/shape_customization/divisor_customization.dart

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

0 commit comments

Comments
 (0)