Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
Implement selection controls demo (#397)
Browse files Browse the repository at this point in the history
* Implement selection controls demo

* Remove Row

* Remove unused import

* Style changes
  • Loading branch information
guidezpl authored Nov 29, 2019
1 parent 1073070 commit 0c3bdf2
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 0 deletions.
41 changes: 41 additions & 0 deletions gallery/lib/data/demos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:gallery/demos/material/button_demo.dart';
import 'package:gallery/demos/material/chip_demo.dart';
import 'package:gallery/demos/material/dialog_demo.dart';
import 'package:gallery/demos/material/list_demo.dart';
import 'package:gallery/demos/material/selection_controls_demo.dart';
import 'package:gallery/demos/material/tabs_demo.dart';
import 'package:gallery/demos/material/text_field_demo.dart';
import 'package:gallery/demos/reference/colors_demo.dart';
Expand Down Expand Up @@ -252,6 +253,46 @@ List<GalleryDemo> materialDemos(BuildContext context) {
),
],
),
GalleryDemo(
title: GalleryLocalizations.of(context).demoSelectionControlsTitle,
icon: GalleryIcons.checkBox,
subtitle: GalleryLocalizations.of(context).demoSelectionControlsSubtitle,
configurations: [
GalleryDemoConfiguration(
title: GalleryLocalizations.of(context)
.demoSelectionControlsCheckboxTitle,
description: GalleryLocalizations.of(context)
.demoSelectionControlsCheckboxDescription,
documentationUrl:
'https://api.flutter.dev/flutter/material/Checkbox-class.html',
buildRoute: (context) => SelectionControlsDemo(
type: SelectionControlsDemoType.checkbox,
),
),
GalleryDemoConfiguration(
title:
GalleryLocalizations.of(context).demoSelectionControlsRadioTitle,
description: GalleryLocalizations.of(context)
.demoSelectionControlsRadioDescription,
documentationUrl:
'https://api.flutter.dev/flutter/material/Radio-class.html',
buildRoute: (context) => SelectionControlsDemo(
type: SelectionControlsDemoType.radio,
),
),
GalleryDemoConfiguration(
title:
GalleryLocalizations.of(context).demoSelectionControlsSwitchTitle,
description: GalleryLocalizations.of(context)
.demoSelectionControlsSwitchDescription,
documentationUrl:
'https://api.flutter.dev/flutter/material/Switch-class.html',
buildRoute: (context) => SelectionControlsDemo(
type: SelectionControlsDemoType.switches,
),
),
],
),
GalleryDemo(
title: GalleryLocalizations.of(context).demoTabsTitle,
icon: GalleryIcons.tabs,
Expand Down
158 changes: 158 additions & 0 deletions gallery/lib/demos/material/selection_controls_demo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';

import 'package:gallery/l10n/gallery_localizations.dart';

enum SelectionControlsDemoType {
checkbox,
radio,
switches,
}

class SelectionControlsDemo extends StatelessWidget {
SelectionControlsDemo({Key key, @required this.type}) : super(key: key);

final SelectionControlsDemoType type;

String _title(BuildContext context) {
switch (type) {
case SelectionControlsDemoType.checkbox:
return GalleryLocalizations.of(context)
.demoSelectionControlsCheckboxTitle;
case SelectionControlsDemoType.radio:
return GalleryLocalizations.of(context).demoSelectionControlsRadioTitle;
case SelectionControlsDemoType.switches:
return GalleryLocalizations.of(context)
.demoSelectionControlsSwitchTitle;
}
return '';
}

@override
Widget build(BuildContext context) {
Widget controls;
switch (type) {
case SelectionControlsDemoType.checkbox:
controls = _CheckboxDemo();
break;
case SelectionControlsDemoType.radio:
controls = _RadioDemo();
break;
case SelectionControlsDemoType.switches:
controls = _SwitchDemo();
break;
}

return Scaffold(
appBar: AppBar(
title: Text(_title(context)),
),
body: controls,
);
}
}

class _CheckboxDemo extends StatefulWidget {
@override
_CheckboxDemoState createState() => _CheckboxDemoState();
}

class _CheckboxDemoState extends State<_CheckboxDemo> {
bool checkboxValueA = true;
bool checkboxValueB = false;
bool checkboxValueC;

@override
Widget build(BuildContext context) {
return Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Checkbox(
value: checkboxValueA,
onChanged: (value) {
setState(() {
checkboxValueA = value;
});
},
),
Checkbox(
value: checkboxValueB,
onChanged: (value) {
setState(() {
checkboxValueB = value;
});
},
),
Checkbox(
value: checkboxValueC,
tristate: true,
onChanged: (value) {
setState(() {
checkboxValueC = value;
});
},
),
],
),
);
}
}

class _RadioDemo extends StatefulWidget {
@override
_RadioDemoState createState() => _RadioDemoState();
}

class _RadioDemoState extends State<_RadioDemo> {
int radioValue = 0;

void handleRadioValueChanged(int value) {
setState(() {
radioValue = value;
});
}

@override
Widget build(BuildContext context) {
return Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
for (int index = 0; index < 3; ++index)
Radio<int>(
value: index,
groupValue: radioValue,
onChanged: handleRadioValueChanged,
),
],
),
);
}
}

class _SwitchDemo extends StatefulWidget {
@override
_SwitchDemoState createState() => _SwitchDemoState();
}

class _SwitchDemoState extends State<_SwitchDemo> {
bool switchValue = false;

@override
Widget build(BuildContext context) {
return Center(
child: Switch(
value: switchValue,
onChanged: (value) {
setState(() {
switchValue = value;
});
},
),
);
}
}
63 changes: 63 additions & 0 deletions gallery/lib/l10n/gallery_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,69 @@ class GalleryLocalizations {
desc: r'Title for the raised button component demo.');
}

String get demoSelectionControlsCheckboxDescription {
return Intl.message(
r'Checkboxes allow the user to select multiple options from a set. A normal checkbox'
"'"
r's value is true or false and a tristate checkbox'
"'"
r's value can also be null.',
locale: _localeName,
name: 'demoSelectionControlsCheckboxDescription',
desc: r'Description for the checkbox (selection controls) demo.');
}

String get demoSelectionControlsCheckboxTitle {
return Intl.message(r'Checkbox',
locale: _localeName,
name: 'demoSelectionControlsCheckboxTitle',
desc: r'Title for the checkbox (selection controls) demo.');
}

String get demoSelectionControlsRadioDescription {
return Intl.message(
r'Radio buttons allow the user to select one option from a set. Use radio buttons for exclusive selection if you think that the user needs to see all available options side-by-side.',
locale: _localeName,
name: 'demoSelectionControlsRadioDescription',
desc: r'Description for the radio button (selection controls) demo.');
}

String get demoSelectionControlsRadioTitle {
return Intl.message(r'Radio',
locale: _localeName,
name: 'demoSelectionControlsRadioTitle',
desc: r'Title for the radio button (selection controls) demo.');
}

String get demoSelectionControlsSubtitle {
return Intl.message(r'Checkboxes, radio buttons, and switches',
locale: _localeName,
name: 'demoSelectionControlsSubtitle',
desc: r'Subtitle for selection controls demo.');
}

String get demoSelectionControlsSwitchDescription {
return Intl.message(
r'On/off switches toggle the state of a single settings option. The option that the switch controls, as well as the state it’s in, should be made clear from the corresponding inline label.',
locale: _localeName,
name: 'demoSelectionControlsSwitchDescription',
desc: r'Description for the switches (selection controls) demo.');
}

String get demoSelectionControlsSwitchTitle {
return Intl.message(r'Switch',
locale: _localeName,
name: 'demoSelectionControlsSwitchTitle',
desc: r'Title for the switches (selection controls) demo.');
}

String get demoSelectionControlsTitle {
return Intl.message(r'Selection controls',
locale: _localeName,
name: 'demoSelectionControlsTitle',
desc: r'Title for selection controls demo.');
}

String get demoSimpleDialogDescription {
return Intl.message(
r'A simple dialog offers the user a choice between several options. A simple dialog has an optional title that is displayed above the choices.',
Expand Down
32 changes: 32 additions & 0 deletions gallery/lib/l10n/intl_en_US.arb
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,38 @@
"@demoTabsDescription": {
"description": "Description for tabs demo."
},
"demoSelectionControlsTitle": "Selection controls",
"@demoSelectionControlsTitle": {
"description": "Title for selection controls demo."
},
"demoSelectionControlsSubtitle": "Checkboxes, radio buttons, and switches",
"@demoSelectionControlsSubtitle": {
"description": "Subtitle for selection controls demo."
},
"demoSelectionControlsCheckboxTitle": "Checkbox",
"@demoSelectionControlsCheckboxTitle": {
"description": "Title for the checkbox (selection controls) demo."
},
"demoSelectionControlsCheckboxDescription": "Checkboxes allow the user to select multiple options from a set. A normal checkbox's value is true or false and a tristate checkbox's value can also be null.",
"@demoSelectionControlsCheckboxDescription": {
"description": "Description for the checkbox (selection controls) demo."
},
"demoSelectionControlsRadioTitle": "Radio",
"@demoSelectionControlsRadioTitle": {
"description": "Title for the radio button (selection controls) demo."
},
"demoSelectionControlsRadioDescription": "Radio buttons allow the user to select one option from a set. Use radio buttons for exclusive selection if you think that the user needs to see all available options side-by-side.",
"@demoSelectionControlsRadioDescription": {
"description": "Description for the radio button (selection controls) demo."
},
"demoSelectionControlsSwitchTitle": "Switch",
"@demoSelectionControlsSwitchTitle": {
"description": "Title for the switches (selection controls) demo."
},
"demoSelectionControlsSwitchDescription": "On/off switches toggle the state of a single settings option. The option that the switch controls, as well as the state it’s in, should be made clear from the corresponding inline label.",
"@demoSelectionControlsSwitchDescription": {
"description": "Description for the switches (selection controls) demo."
},
"demoBottomTextFieldsTitle": "Text fields",
"@demoBottomTextFieldsTitle": {
"description": "Title for text fields demo."
Expand Down
32 changes: 32 additions & 0 deletions gallery/lib/l10n/intl_en_US.xml
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,38 @@
name="demoTabsDescription"
description="Description for tabs demo."
>Tabs organize content across different screens, data sets, and other interactions.</string>
<string
name="demoSelectionControlsTitle"
description="Title for selection controls demo."
>Selection controls</string>
<string
name="demoSelectionControlsSubtitle"
description="Subtitle for selection controls demo."
>Checkboxes, radio buttons, and switches</string>
<string
name="demoSelectionControlsCheckboxTitle"
description="Title for the checkbox (selection controls) demo."
>Checkbox</string>
<string
name="demoSelectionControlsCheckboxDescription"
description="Description for the checkbox (selection controls) demo."
>Checkboxes allow the user to select multiple options from a set. A normal checkbox&apos;s value is true or false and a tristate checkbox&apos;s value can also be null.</string>
<string
name="demoSelectionControlsRadioTitle"
description="Title for the radio button (selection controls) demo."
>Radio</string>
<string
name="demoSelectionControlsRadioDescription"
description="Description for the radio button (selection controls) demo."
>Radio buttons allow the user to select one option from a set. Use radio buttons for exclusive selection if you think that the user needs to see all available options side-by-side.</string>
<string
name="demoSelectionControlsSwitchTitle"
description="Title for the switches (selection controls) demo."
>Switch</string>
<string
name="demoSelectionControlsSwitchDescription"
description="Description for the switches (selection controls) demo."
>On/off switches toggle the state of a single settings option. The option that the switch controls, as well as the state it’s in, should be made clear from the corresponding inline label.</string>
<string
name="demoBottomTextFieldsTitle"
description="Title for text fields demo."
Expand Down
19 changes: 19 additions & 0 deletions gallery/lib/l10n/messages_en_US.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,25 @@ class MessageLookup extends MessageLookupByLibrary {
"Raised buttons add dimension to mostly flat layouts. They emphasize functions on busy or wide spaces."),
"demoRaisedButtonTitle":
MessageLookupByLibrary.simpleMessage("Raised Button"),
"demoSelectionControlsCheckboxDescription":
MessageLookupByLibrary.simpleMessage(
"Checkboxes allow the user to select multiple options from a set. A normal checkbox\'s value is true or false and a tristate checkbox\'s value can also be null."),
"demoSelectionControlsCheckboxTitle":
MessageLookupByLibrary.simpleMessage("Checkbox"),
"demoSelectionControlsRadioDescription":
MessageLookupByLibrary.simpleMessage(
"Radio buttons allow the user to select one option from a set. Use radio buttons for exclusive selection if you think that the user needs to see all available options side-by-side."),
"demoSelectionControlsRadioTitle":
MessageLookupByLibrary.simpleMessage("Radio"),
"demoSelectionControlsSubtitle": MessageLookupByLibrary.simpleMessage(
"Checkboxes, radio buttons, and switches"),
"demoSelectionControlsSwitchDescription":
MessageLookupByLibrary.simpleMessage(
"On/off switches toggle the state of a single settings option. The option that the switch controls, as well as the state it’s in, should be made clear from the corresponding inline label."),
"demoSelectionControlsSwitchTitle":
MessageLookupByLibrary.simpleMessage("Switch"),
"demoSelectionControlsTitle":
MessageLookupByLibrary.simpleMessage("Selection controls"),
"demoSimpleDialogDescription": MessageLookupByLibrary.simpleMessage(
"A simple dialog offers the user a choice between several options. A simple dialog has an optional title that is displayed above the choices."),
"demoSimpleDialogTitle": MessageLookupByLibrary.simpleMessage("Simple"),
Expand Down

0 comments on commit 0c3bdf2

Please sign in to comment.