Skip to content

Commit

Permalink
Remove PageState from example app
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Aug 20, 2022
1 parent 57c9527 commit cedd8f2
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 95 deletions.
66 changes: 32 additions & 34 deletions example/lib/screens/inputs/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import 'package:fluent_ui/fluent_ui.dart';
import '../../widgets/card_highlight.dart';

class ButtonPage extends ScrollablePage {
PageState state = <String, dynamic>{
'simple_disabled': false,
'filled_disabled': false,
'icon_disabled': false,
'toggle_state': false,
'toggle_disabled': false,
'split_button_disabled': false,
'radio_button_disabled': false,
'radio_button_selected': -1,
};
bool simpleDisabled = false;
bool filledDisabled = false;
bool iconDisabled = false;
bool toggleDisabled = false;
bool toggleState = false;
bool splitButtonDisabled = false;
bool radioButtonDisabled = false;
int radioButtonSelected = -1;

@override
Widget buildHeader(BuildContext context) {
Expand All @@ -33,14 +31,14 @@ class ButtonPage extends ScrollablePage {
child: Row(children: [
Button(
child: const Text('Standart Button'),
onPressed: state['simple_disabled'] ? null : () {},
onPressed: simpleDisabled ? null : () {},
),
const Spacer(),
ToggleSwitch(
checked: state['simple_disabled'],
checked: simpleDisabled,
onChanged: (v) {
setState(() {
state['simple_disabled'] = v;
simpleDisabled = v;
});
},
content: const Text('Disabled'),
Expand All @@ -56,14 +54,14 @@ class ButtonPage extends ScrollablePage {
child: Row(children: [
FilledButton(
child: const Text('Filled Button'),
onPressed: state['filled_disabled'] ? null : () {},
onPressed: filledDisabled ? null : () {},
),
const Spacer(),
ToggleSwitch(
checked: state['filled_disabled'],
checked: filledDisabled,
onChanged: (v) {
setState(() {
state['filled_disabled'] = v;
filledDisabled = v;
});
},
content: const Text('Disabled'),
Expand All @@ -81,14 +79,14 @@ class ButtonPage extends ScrollablePage {
child: Row(children: [
IconButton(
icon: const Icon(FluentIcons.graph_symbol, size: 24.0),
onPressed: state['icon_disabled'] ? null : () {},
onPressed: iconDisabled ? null : () {},
),
const Spacer(),
ToggleSwitch(
checked: state['icon_disabled'],
checked: iconDisabled,
onChanged: (v) {
setState(() {
state['icon_disabled'] = v;
iconDisabled = v;
});
},
content: const Text('Disabled'),
Expand All @@ -107,21 +105,21 @@ class ButtonPage extends ScrollablePage {
child: Row(children: [
ToggleButton(
child: const Text('Toggle Button'),
checked: state['toggle_state'],
onChanged: state['toggle_disabled']
checked: toggleState,
onChanged: toggleDisabled
? null
: (v) {
setState(() {
state['toggle_state'] = v;
toggleState = v;
});
},
),
const Spacer(),
ToggleSwitch(
checked: state['toggle_disabled'],
checked: toggleDisabled,
onChanged: (v) {
setState(() {
state['toggle_disabled'] = v;
toggleDisabled = v;
});
},
content: const Text('Disabled'),
Expand Down Expand Up @@ -189,7 +187,7 @@ ToggleButton(
Button(
child: Container(
decoration: BoxDecoration(
color: state['split_button_disabled']
color: splitButtonDisabled
? FluentTheme.of(context).accentColor.darker
: FluentTheme.of(context).accentColor,
borderRadius: const BorderRadiusDirectional.horizontal(
Expand All @@ -199,23 +197,23 @@ ToggleButton(
height: 24,
width: 24,
),
onPressed: state['split_button_disabled'] ? null : () {},
onPressed: splitButtonDisabled ? null : () {},
),
IconButton(
icon: const SizedBox(
// height: splitButtonHeight,
child: Icon(FluentIcons.chevron_down, size: 10.0),
),
onPressed: state['split_button_disabled'] ? null : () {},
onPressed: splitButtonDisabled ? null : () {},
),
],
),
const Spacer(),
ToggleSwitch(
checked: state['split_button_disabled'],
checked: splitButtonDisabled,
onChanged: (v) {
setState(() {
state['split_button_disabled'] = v;
splitButtonDisabled = v;
});
},
content: const Text('Disabled'),
Expand Down Expand Up @@ -253,13 +251,13 @@ ToggleButton(
return Padding(
padding: EdgeInsets.only(bottom: index == 2 ? 0.0 : 14.0),
child: RadioButton(
checked: state['radio_button_selected'] == index,
onChanged: state['radio_button_disabled']
checked: radioButtonSelected == index,
onChanged: radioButtonDisabled
? null
: (v) {
if (v) {
setState(() {
state['radio_button_selected'] = index;
radioButtonSelected = index;
});
}
},
Expand All @@ -271,10 +269,10 @@ ToggleButton(
),
const Spacer(),
ToggleSwitch(
checked: state['radio_button_disabled'],
checked: radioButtonDisabled,
onChanged: (v) {
setState(() {
state['radio_button_disabled'] = v;
radioButtonDisabled = v;
});
},
content: const Text('Disabled'),
Expand Down
32 changes: 15 additions & 17 deletions example/lib/screens/inputs/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import 'package:example/widgets/page.dart';
import 'package:fluent_ui/fluent_ui.dart';

class CheckboxPage extends ScrollablePage {
PageState state = <String, dynamic>{
'first_checked': false,
'first_disabled': false,
'second_state': false,
'second_disabled': false,
'icon_disabled': false,
};
bool firstChecked = false;
bool firstDisabled = false;
bool? secondChecked = false;
bool secondDisabled = false;
bool iconDisabled = false;

@override
Widget buildHeader(BuildContext context) {
Expand All @@ -26,22 +24,22 @@ class CheckboxPage extends ScrollablePage {
CardHighlight(
child: Row(children: [
Checkbox(
checked: state['first_checked'],
onChanged: state['first_disabled']
checked: firstChecked,
onChanged: firstDisabled
? null
: (v) {
setState(() {
state['first_checked'] = v;
firstChecked = v!;
});
},
content: const Text('Two-state Checkbox'),
),
const Spacer(),
ToggleSwitch(
checked: state['first_disabled'],
checked: firstDisabled,
onChanged: (v) {
setState(() {
state['first_disabled'] = v;
firstDisabled = v;
});
},
content: const Text('Disabled'),
Expand All @@ -58,13 +56,13 @@ Checkbox(
CardHighlight(
child: Row(children: [
Checkbox(
checked: state['second_state'],
checked: secondChecked,
// checked: null,
onChanged: state['second_disabled']
onChanged: secondDisabled
? null
: (v) {
setState(() {
state['second_state'] = v == true
secondChecked = v == true
? true
: v == false
? null
Expand All @@ -77,10 +75,10 @@ Checkbox(
),
const Spacer(),
ToggleSwitch(
checked: state['second_disabled'],
checked: secondDisabled,
onChanged: (v) {
setState(() {
state['second_disabled'] = v;
secondDisabled = v;
});
},
content: const Text('Disabled'),
Expand Down
37 changes: 15 additions & 22 deletions example/lib/screens/inputs/slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ import 'package:example/widgets/page.dart';
import 'package:fluent_ui/fluent_ui.dart';

class SliderPage extends ScrollablePage {
PageState state = <String, dynamic>{
'disabled': false,
'first_value': 23.0,
'vertical_value': 50.0,
};
bool disabled = false;
double firstValue = 23.0;
double verticalValue = 50.0;

@override
Widget buildHeader(BuildContext context) {
return PageHeader(
title: const Text('Slider'),
commandBar: ToggleSwitch(
checked: isDisabled,
onChanged: (v) => setState(() => state['disabled'] = v),
checked: disabled,
onChanged: (v) => setState(() => disabled = v),
content: const Text('Disabled'),
),
);
}

bool get isDisabled => state['disabled'];

@override
List<Widget> buildScrollable(BuildContext context) {
return [
Expand All @@ -32,16 +28,16 @@ class SliderPage extends ScrollablePage {
CardHighlight(
child: Row(children: [
Slider(
label: '${state['first_value'].toInt()}',
value: state['first_value'],
onChanged: isDisabled
label: '${firstValue.toInt()}',
value: firstValue,
onChanged: disabled
? null
: (v) {
setState(() => state['first_value'] = v);
setState(() => firstValue = v);
},
),
const Spacer(),
Text('Output:\n${state['first_value'].toInt()}'),
Text('Output:\n${firstValue.toInt()}'),
]),
codeSnippet: '''double value = 0;
Expand All @@ -57,16 +53,13 @@ Slider(
child: Row(children: [
Slider(
vertical: true,
label: '${state['vertical_value'].toInt()}',
value: state['vertical_value'],
onChanged: isDisabled
? null
: (v) {
setState(() => state['vertical_value'] = v);
},
label: '${verticalValue.toInt()}',
value: verticalValue,
onChanged:
disabled ? null : (v) => setState(() => verticalValue = v),
),
const Spacer(),
Text('Output:\n${state['vertical_value'].toInt()}'),
Text('Output:\n${verticalValue.toInt()}'),
]),
codeSnippet: '''double value = 0;
Expand Down
32 changes: 14 additions & 18 deletions example/lib/screens/inputs/toggle_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ import 'package:fluent_ui/fluent_ui.dart';
import 'package:example/widgets/card_highlight.dart';

class ToggleSwitchPage extends ScrollablePage {
PageState state = <String, dynamic>{
'disabled': false,
'first_value': false,
'second_value': true,
};
bool disabled = false;
bool firstValue = false;
bool secondValue = true;

@override
Widget buildHeader(BuildContext context) {
return PageHeader(
title: const Text('ToggleSwitch'),
commandBar: ToggleSwitch(
checked: isDisabled,
onChanged: (v) => setState(() => state['disabled'] = v),
checked: disabled,
onChanged: (v) => setState(() => disabled = v),
content: const Text('Disabled'),
),
);
}

bool get isDisabled => state['disabled'];

@override
List<Widget> buildScrollable(BuildContext context) {
return [
Expand All @@ -34,13 +30,13 @@ class ToggleSwitchPage extends ScrollablePage {
child: Align(
alignment: Alignment.centerLeft,
child: ToggleSwitch(
checked: state['first_value'],
onChanged: isDisabled
checked: firstValue,
onChanged: disabled
? null
: (v) {
setState(() => state['first_value'] = v);
setState(() => firstValue = v);
},
content: Text(state['first_value'] ? 'On' : 'Off'),
content: Text(firstValue ? 'On' : 'Off'),
),
),
codeSnippet: '''bool checked = false;
Expand All @@ -58,16 +54,16 @@ ToggleSwitch(
InfoLabel(
label: 'Header',
child: ToggleSwitch(
checked: state['second_value'],
onChanged: isDisabled
checked: secondValue,
onChanged: disabled
? null
: (v) {
setState(() => state['second_value'] = v);
setState(() => secondValue = v);
},
content: Text(state['second_value'] ? 'Working' : 'Do work'),
content: Text(secondValue ? 'Working' : 'Do work'),
),
),
if (state['second_value'])
if (secondValue)
const Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: ProgressRing(),
Expand Down
Loading

0 comments on commit cedd8f2

Please sign in to comment.