parent
f0f99a45d9
commit
b1a7720315
@ -12,7 +12,7 @@ import 'shrine_page.dart';
|
|||||||
import 'shrine_theme.dart';
|
import 'shrine_theme.dart';
|
||||||
import 'shrine_types.dart';
|
import 'shrine_types.dart';
|
||||||
|
|
||||||
const double unitSize = kToolBarHeight;
|
const double unitSize = kToolbarHeight;
|
||||||
|
|
||||||
final List<Product> _products = new List<Product>.from(allProducts());
|
final List<Product> _products = new List<Product>.from(allProducts());
|
||||||
final Map<Product, Order> _shoppingCart = <Product, Order>{};
|
final Map<Product, Order> _shoppingCart = <Product, Order>{};
|
||||||
|
@ -24,14 +24,14 @@ abstract class AppBarBottomWidget extends Widget {
|
|||||||
double get bottomHeight;
|
double get bottomHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum _ToolBarSlot {
|
enum _ToolbarSlot {
|
||||||
leading,
|
leading,
|
||||||
title,
|
title,
|
||||||
actions,
|
actions,
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ToolBarLayout extends MultiChildLayoutDelegate {
|
class _ToolbarLayout extends MultiChildLayoutDelegate {
|
||||||
_ToolBarLayout({ this.centerTitle });
|
_ToolbarLayout({ this.centerTitle });
|
||||||
|
|
||||||
// If false the title should be left or right justified within the space bewteen
|
// If false the title should be left or right justified within the space bewteen
|
||||||
// the leading and actions widgets, depending on the locale's writing direction.
|
// the leading and actions widgets, depending on the locale's writing direction.
|
||||||
@ -46,22 +46,22 @@ class _ToolBarLayout extends MultiChildLayoutDelegate {
|
|||||||
void performLayout(Size size) {
|
void performLayout(Size size) {
|
||||||
double actionsWidth = 0.0;
|
double actionsWidth = 0.0;
|
||||||
|
|
||||||
if (hasChild(_ToolBarSlot.leading)) {
|
if (hasChild(_ToolbarSlot.leading)) {
|
||||||
final BoxConstraints constraints = new BoxConstraints.tight(new Size(kLeadingWidth, size.height));
|
final BoxConstraints constraints = new BoxConstraints.tight(new Size(kLeadingWidth, size.height));
|
||||||
layoutChild(_ToolBarSlot.leading, constraints);
|
layoutChild(_ToolbarSlot.leading, constraints);
|
||||||
positionChild(_ToolBarSlot.leading, Offset.zero);
|
positionChild(_ToolbarSlot.leading, Offset.zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasChild(_ToolBarSlot.actions)) {
|
if (hasChild(_ToolbarSlot.actions)) {
|
||||||
final BoxConstraints constraints = new BoxConstraints.loose(size);
|
final BoxConstraints constraints = new BoxConstraints.loose(size);
|
||||||
actionsWidth = layoutChild(_ToolBarSlot.actions, constraints).width;
|
actionsWidth = layoutChild(_ToolbarSlot.actions, constraints).width;
|
||||||
positionChild(_ToolBarSlot.actions, new Offset(size.width - actionsWidth, 0.0));
|
positionChild(_ToolbarSlot.actions, new Offset(size.width - actionsWidth, 0.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasChild(_ToolBarSlot.title)) {
|
if (hasChild(_ToolbarSlot.title)) {
|
||||||
final double maxWidth = size.width - kTitleLeft - actionsWidth;
|
final double maxWidth = size.width - kTitleLeft - actionsWidth;
|
||||||
final BoxConstraints constraints = new BoxConstraints.loose(size).copyWith(maxWidth: maxWidth);
|
final BoxConstraints constraints = new BoxConstraints.loose(size).copyWith(maxWidth: maxWidth);
|
||||||
final Size titleSize = layoutChild(_ToolBarSlot.title, constraints);
|
final Size titleSize = layoutChild(_ToolbarSlot.title, constraints);
|
||||||
final double titleY = (size.height - titleSize.height) / 2.0;
|
final double titleY = (size.height - titleSize.height) / 2.0;
|
||||||
double titleX = kTitleLeft;
|
double titleX = kTitleLeft;
|
||||||
|
|
||||||
@ -75,12 +75,12 @@ class _ToolBarLayout extends MultiChildLayoutDelegate {
|
|||||||
titleX = kTitleLeft;
|
titleX = kTitleLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
positionChild(_ToolBarSlot.title, new Offset(titleX, titleY));
|
positionChild(_ToolbarSlot.title, new Offset(titleX, titleY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRelayout(_ToolBarLayout oldDelegate) => centerTitle != oldDelegate.centerTitle;
|
bool shouldRelayout(_ToolbarLayout oldDelegate) => centerTitle != oldDelegate.centerTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(eseidel) Toolbar needs to change size based on orientation:
|
// TODO(eseidel) Toolbar needs to change size based on orientation:
|
||||||
@ -287,7 +287,7 @@ class AppBar extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
double get _toolBarHeight => kToolBarHeight;
|
double get _toolbarHeight => kToolbarHeight;
|
||||||
|
|
||||||
/// The height of the bottom widget. The [Scaffold] uses this value to control
|
/// The height of the bottom widget. The [Scaffold] uses this value to control
|
||||||
/// the size of the app bar when its appBarBehavior is [AppBarBehavior.scroll]
|
/// the size of the app bar when its appBarBehavior is [AppBarBehavior.scroll]
|
||||||
@ -300,16 +300,16 @@ class AppBar extends StatelessWidget {
|
|||||||
/// enough to accommodate whatever that widget contains.
|
/// enough to accommodate whatever that widget contains.
|
||||||
///
|
///
|
||||||
/// See also [getExpandedHeightFor].
|
/// See also [getExpandedHeightFor].
|
||||||
double get expandedHeight => _expandedHeight ?? (_toolBarHeight + bottomHeight);
|
double get expandedHeight => _expandedHeight ?? (_toolbarHeight + bottomHeight);
|
||||||
|
|
||||||
/// By default, the height of the toolbar and the bottom widget (if any).
|
/// By default, the height of the toolbar and the bottom widget (if any).
|
||||||
/// If the height of the app bar is constrained to be less than this value
|
/// If the height of the app bar is constrained to be less than this value
|
||||||
/// then the toolbar and bottom widget are scrolled upwards, out of view.
|
/// then the toolbar and bottom widget are scrolled upwards, out of view.
|
||||||
double get collapsedHeight => _collapsedHeight ?? (_toolBarHeight + bottomHeight);
|
double get collapsedHeight => _collapsedHeight ?? (_toolbarHeight + bottomHeight);
|
||||||
|
|
||||||
// Defines the opacity of the toolbar's text and icons.
|
// Defines the opacity of the toolbar's text and icons.
|
||||||
double _toolBarOpacity(double appBarHeight, double statusBarHeight) {
|
double _toolbarOpacity(double appBarHeight, double statusBarHeight) {
|
||||||
return ((appBarHeight - bottomHeight - statusBarHeight) / _toolBarHeight).clamp(0.0, 1.0);
|
return ((appBarHeight - bottomHeight - statusBarHeight) / _toolbarHeight).clamp(0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
double _bottomOpacity(double appBarHeight, double statusBarHeight) {
|
double _bottomOpacity(double appBarHeight, double statusBarHeight) {
|
||||||
@ -345,9 +345,9 @@ class AppBar extends StatelessWidget {
|
|||||||
? mojom.SystemUiOverlayStyle.light
|
? mojom.SystemUiOverlayStyle.light
|
||||||
: mojom.SystemUiOverlayStyle.dark);
|
: mojom.SystemUiOverlayStyle.dark);
|
||||||
|
|
||||||
final double toolBarOpacity = _toolBarOpacity(size.height, statusBarHeight);
|
final double toolbarOpacity = _toolbarOpacity(size.height, statusBarHeight);
|
||||||
if (toolBarOpacity != 1.0) {
|
if (toolbarOpacity != 1.0) {
|
||||||
final double opacity = const Interval(0.25, 1.0, curve: Curves.fastOutSlowIn).transform(toolBarOpacity);
|
final double opacity = const Interval(0.25, 1.0, curve: Curves.fastOutSlowIn).transform(toolbarOpacity);
|
||||||
if (centerStyle?.color != null)
|
if (centerStyle?.color != null)
|
||||||
centerStyle = centerStyle.copyWith(color: centerStyle.color.withOpacity(opacity));
|
centerStyle = centerStyle.copyWith(color: centerStyle.color.withOpacity(opacity));
|
||||||
if (sideStyle?.color != null)
|
if (sideStyle?.color != null)
|
||||||
@ -357,19 +357,19 @@ class AppBar extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Widget> toolBarChildren = <Widget>[];
|
final List<Widget> toolbarChildren = <Widget>[];
|
||||||
if (leading != null) {
|
if (leading != null) {
|
||||||
toolBarChildren.add(
|
toolbarChildren.add(
|
||||||
new LayoutId(
|
new LayoutId(
|
||||||
id: _ToolBarSlot.leading,
|
id: _ToolbarSlot.leading,
|
||||||
child: leading
|
child: leading
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
toolBarChildren.add(
|
toolbarChildren.add(
|
||||||
new LayoutId(
|
new LayoutId(
|
||||||
id: _ToolBarSlot.title,
|
id: _ToolbarSlot.title,
|
||||||
child: new DefaultTextStyle(
|
child: new DefaultTextStyle(
|
||||||
style: centerStyle,
|
style: centerStyle,
|
||||||
softWrap: false,
|
softWrap: false,
|
||||||
@ -380,9 +380,9 @@ class AppBar extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (actions != null && actions.isNotEmpty) {
|
if (actions != null && actions.isNotEmpty) {
|
||||||
toolBarChildren.add(
|
toolbarChildren.add(
|
||||||
new LayoutId(
|
new LayoutId(
|
||||||
id: _ToolBarSlot.actions,
|
id: _ToolbarSlot.actions,
|
||||||
child: new Row(
|
child: new Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: actions
|
children: actions
|
||||||
@ -391,24 +391,24 @@ class AppBar extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget toolBar = new Padding(
|
Widget toolbar = new Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
child: new CustomMultiChildLayout(
|
child: new CustomMultiChildLayout(
|
||||||
delegate: new _ToolBarLayout(
|
delegate: new _ToolbarLayout(
|
||||||
centerTitle: _getEffectiveCenterTitle(themeData)
|
centerTitle: _getEffectiveCenterTitle(themeData)
|
||||||
),
|
),
|
||||||
children: toolBarChildren
|
children: toolbarChildren
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
Widget appBar = new SizedBox(
|
Widget appBar = new SizedBox(
|
||||||
height: kToolBarHeight,
|
height: kToolbarHeight,
|
||||||
child: new IconTheme.merge(
|
child: new IconTheme.merge(
|
||||||
context: context,
|
context: context,
|
||||||
data: appBarIconTheme,
|
data: appBarIconTheme,
|
||||||
child: new DefaultTextStyle(
|
child: new DefaultTextStyle(
|
||||||
style: sideStyle,
|
style: sideStyle,
|
||||||
child: toolBar
|
child: toolbar
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
/// The height of the tool bar component of the [AppBar].
|
/// The height of the toolbar component of the [AppBar].
|
||||||
const double kToolBarHeight = 56.0;
|
const double kToolbarHeight = 56.0;
|
||||||
|
|
||||||
/// The height of a tab bar containing text.
|
/// The height of a tab bar containing text.
|
||||||
const double kTextTabBarHeight = 48.0;
|
const double kTextTabBarHeight = 48.0;
|
||||||
|
@ -78,7 +78,7 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
|
|||||||
|
|
||||||
final double currentHeight = size.height;
|
final double currentHeight = size.height;
|
||||||
final double maxHeight = statusBarHeight + AppBar.getExpandedHeightFor(context);
|
final double maxHeight = statusBarHeight + AppBar.getExpandedHeightFor(context);
|
||||||
final double minHeight = statusBarHeight + kToolBarHeight;
|
final double minHeight = statusBarHeight + kToolbarHeight;
|
||||||
final double deltaHeight = maxHeight - minHeight;
|
final double deltaHeight = maxHeight - minHeight;
|
||||||
|
|
||||||
// 0.0 -> Expanded
|
// 0.0 -> Expanded
|
||||||
@ -89,7 +89,7 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
|
|||||||
|
|
||||||
// background image
|
// background image
|
||||||
if (config.background != null) {
|
if (config.background != null) {
|
||||||
final double fadeStart = math.max(0.0, 1.0 - kToolBarHeight / deltaHeight);
|
final double fadeStart = math.max(0.0, 1.0 - kToolbarHeight / deltaHeight);
|
||||||
final double fadeEnd = 1.0;
|
final double fadeEnd = 1.0;
|
||||||
assert(fadeStart <= fadeEnd);
|
assert(fadeStart <= fadeEnd);
|
||||||
final double opacity = 1.0 - new Interval(fadeStart, fadeEnd).transform(t);
|
final double opacity = 1.0 - new Interval(fadeStart, fadeEnd).transform(t);
|
||||||
@ -110,7 +110,7 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
|
|||||||
|
|
||||||
if (config.title != null) {
|
if (config.title != null) {
|
||||||
final ThemeData theme = Theme.of(context);
|
final ThemeData theme = Theme.of(context);
|
||||||
final double opacity = (1.0 - (minHeight - currentHeight) / (kToolBarHeight - statusBarHeight)).clamp(0.0, 1.0);
|
final double opacity = (1.0 - (minHeight - currentHeight) / (kToolbarHeight - statusBarHeight)).clamp(0.0, 1.0);
|
||||||
if (opacity > 0.0) {
|
if (opacity > 0.0) {
|
||||||
TextStyle titleStyle = theme.primaryTextTheme.title;
|
TextStyle titleStyle = theme.primaryTextTheme.title;
|
||||||
titleStyle = titleStyle.copyWith(
|
titleStyle = titleStyle.copyWith(
|
||||||
|
@ -41,7 +41,7 @@ enum TextSelectionHandleType {
|
|||||||
/// Builds a selection handle of the given type.
|
/// Builds a selection handle of the given type.
|
||||||
typedef Widget TextSelectionHandleBuilder(BuildContext context, TextSelectionHandleType type);
|
typedef Widget TextSelectionHandleBuilder(BuildContext context, TextSelectionHandleType type);
|
||||||
|
|
||||||
/// Builds a tool bar near a text selection.
|
/// Builds a toolbar near a text selection.
|
||||||
///
|
///
|
||||||
/// Typically displays buttons for copying and pasting text.
|
/// Typically displays buttons for copying and pasting text.
|
||||||
// TODO(mpcomplete): A single position is probably insufficient.
|
// TODO(mpcomplete): A single position is probably insufficient.
|
||||||
@ -110,9 +110,9 @@ class TextSelectionOverlay implements TextSelectionDelegate {
|
|||||||
/// selected.
|
/// selected.
|
||||||
final TextSelectionHandleBuilder handleBuilder;
|
final TextSelectionHandleBuilder handleBuilder;
|
||||||
|
|
||||||
/// Builds a tool bar to display near the selection.
|
/// Builds a toolbar to display near the selection.
|
||||||
///
|
///
|
||||||
/// The tool bar typically contains buttons for copying and pasting text.
|
/// The toolbar typically contains buttons for copying and pasting text.
|
||||||
final TextSelectionToolbarBuilder toolbarBuilder;
|
final TextSelectionToolbarBuilder toolbarBuilder;
|
||||||
|
|
||||||
/// Controls the fade-in animations.
|
/// Controls the fade-in animations.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user