mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

Anywhere that accepted IconData now accepts either an Icon or an ImageIcon. Places that used to take an IconData in an `icon` argument, notably IconButton and DrawerItem, now take a Widget in that slot. You can wrap the value that used to be passed in in an Icon constructor to get the same result. Icon itself now takes the icon as a positional argument, for brevity. ThemeData now has an iconTheme as well as a primaryIconTheme, the same way it has had a textTheme and primaryTextTheme for a while. IconTheme.of() always returns a value now (though that value itself may have nulls in it). It defaults to the ThemeData.iconTheme. IconThemeData.fallback() is a new method that returns an icon theme data structure with all fields filled in. IconTheme.merge() is a new constructor that takes a context and creates a widget that mixes in the new values with the inherited values. Most places that introduced an IconTheme widget now use IconTheme.merge. IconThemeData.merge and IconThemeData.copyWith act in a way analogous to the similarly-named members of TextStyle. ImageIcon is introduced. It acts like Icon but takes an ImageProvider instead of an IconData. Also: Fix the analyzer to actually check the stocks app.
200 lines
5.4 KiB
Dart
200 lines
5.4 KiB
Dart
// Copyright 2016 The Chromium Authors. 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 '../gallery/demo.dart';
|
|
|
|
const String _raisedText =
|
|
"# Raised buttons\n"
|
|
"Raised buttons add dimension to mostly flat layouts. They emphasize "
|
|
"functions on busy or wide spaces.";
|
|
|
|
const String _raisedCode = 'buttons_raised';
|
|
|
|
const String _flatText =
|
|
"# Flat buttons\n"
|
|
"A flat button displays an ink splash on press "
|
|
"but does not lift. Use flat buttons on toolbars, in dialogs and "
|
|
"inline with padding";
|
|
|
|
const String _flatCode = 'buttons_flat';
|
|
|
|
const String _dropdownText =
|
|
"# Dropdown buttons\n"
|
|
"A dropdown button displays a menu that's used to select a value from a "
|
|
"small set of values. The button displays the current value and a down "
|
|
"arrow.";
|
|
|
|
const String _dropdownCode = 'buttons_dropdown';
|
|
|
|
const String _iconText =
|
|
"IconButtons are appropriate for toggle buttons that allow a single choice to be "
|
|
"selected or deselected, such as adding or removing an item's star.";
|
|
|
|
const String _iconCode = 'buttons_icon';
|
|
|
|
const String _actionText =
|
|
"# Floating action buttons\n"
|
|
"Floating action buttons are used for a promoted action. They are "
|
|
"distinguished by a circled icon floating above the UI and can have motion "
|
|
"behaviors that include morphing, launching, and a transferring anchor "
|
|
"point.";
|
|
|
|
const String _actionCode = 'buttons_action';
|
|
|
|
class ButtonsDemo extends StatefulWidget {
|
|
static const String routeName = '/buttons';
|
|
|
|
@override
|
|
_ButtonsDemoState createState() => new _ButtonsDemoState();
|
|
}
|
|
|
|
class _ButtonsDemoState extends State<ButtonsDemo> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
List<ComponentDemoTabData> demos = <ComponentDemoTabData>[
|
|
new ComponentDemoTabData(
|
|
tabName: 'RAISED',
|
|
description: _raisedText,
|
|
widget: buildRaisedButton(),
|
|
exampleCodeTag: _raisedCode
|
|
),
|
|
new ComponentDemoTabData(
|
|
tabName: 'FLAT',
|
|
description: _flatText,
|
|
widget: buildFlatButton(),
|
|
exampleCodeTag: _flatCode
|
|
),
|
|
new ComponentDemoTabData(
|
|
tabName: 'DROPDOWN',
|
|
description: _dropdownText,
|
|
widget: buildDropdownButton(),
|
|
exampleCodeTag: _dropdownCode
|
|
),
|
|
new ComponentDemoTabData(
|
|
tabName: 'ICON',
|
|
description: _iconText,
|
|
widget: buildIconButton(),
|
|
exampleCodeTag: _iconCode
|
|
),
|
|
new ComponentDemoTabData(
|
|
tabName: 'ACTION',
|
|
description: _actionText,
|
|
widget: buildActionButton(),
|
|
exampleCodeTag: _actionCode
|
|
),
|
|
];
|
|
|
|
return new TabbedComponentDemoScaffold(
|
|
title: 'Buttons',
|
|
demos: demos
|
|
);
|
|
}
|
|
|
|
Widget buildRaisedButton() {
|
|
return new Align(
|
|
alignment: new FractionalOffset(0.5, 0.4),
|
|
child: new ButtonBar(
|
|
alignment: MainAxisAlignment.collapse,
|
|
children: <Widget>[
|
|
new RaisedButton(
|
|
child: new Text('RAISED BUTTON'),
|
|
onPressed: () {
|
|
// Perform some action
|
|
}
|
|
),
|
|
new RaisedButton(
|
|
child: new Text('DISABLED'),
|
|
onPressed: null
|
|
)
|
|
]
|
|
)
|
|
);
|
|
}
|
|
|
|
Widget buildFlatButton() {
|
|
return new Align(
|
|
alignment: new FractionalOffset(0.5, 0.4),
|
|
child: new ButtonBar(
|
|
alignment: MainAxisAlignment.collapse,
|
|
children: <Widget>[
|
|
new FlatButton(
|
|
child: new Text('FLAT BUTTON'),
|
|
onPressed: () {
|
|
// Perform some action
|
|
}
|
|
),
|
|
new FlatButton(
|
|
child: new Text('DISABLED'),
|
|
onPressed: null
|
|
)
|
|
]
|
|
)
|
|
);
|
|
}
|
|
|
|
String dropdownValue = 'Free';
|
|
|
|
Widget buildDropdownButton() {
|
|
return new Align(
|
|
alignment: new FractionalOffset(0.5, 0.4),
|
|
child: new DropDownButton<String>(
|
|
value: dropdownValue,
|
|
onChanged: (String newValue) {
|
|
setState(() {
|
|
if (newValue != null)
|
|
dropdownValue = newValue;
|
|
});
|
|
},
|
|
items: <String>['One', 'Two', 'Free', 'Four']
|
|
.map((String value) {
|
|
return new DropDownMenuItem<String>(
|
|
value: value,
|
|
child: new Text(value));
|
|
})
|
|
.toList()
|
|
)
|
|
);
|
|
}
|
|
|
|
bool iconButtonToggle = false;
|
|
|
|
Widget buildIconButton() {
|
|
return new Align(
|
|
alignment: new FractionalOffset(0.5, 0.4),
|
|
child: new Row(
|
|
mainAxisAlignment: MainAxisAlignment.collapse,
|
|
children: <Widget>[
|
|
new IconButton(
|
|
icon: new Icon(Icons.thumb_up),
|
|
onPressed: () {
|
|
setState(() => iconButtonToggle = !iconButtonToggle);
|
|
},
|
|
color: iconButtonToggle ? Theme.of(context).primaryColor : null
|
|
),
|
|
new IconButton(
|
|
icon: new Icon(Icons.thumb_up),
|
|
onPressed: null
|
|
)
|
|
]
|
|
.map((Widget button) => new SizedBox(width: 64.0, height: 64.0, child: button))
|
|
.toList()
|
|
)
|
|
);
|
|
}
|
|
|
|
Widget buildActionButton() {
|
|
return new Align(
|
|
alignment: new FractionalOffset(0.5, 0.4),
|
|
child: new FloatingActionButton(
|
|
child: new Icon(Icons.add),
|
|
onPressed: () {
|
|
// Perform some action
|
|
}
|
|
)
|
|
);
|
|
}
|
|
}
|