Skip to content

Commit

Permalink
Add a constant for padding in a Material ListView (flutter#8918)
Browse files Browse the repository at this point in the history
  • Loading branch information
abarth authored Mar 20, 2017
1 parent 31fd742 commit 269538d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/flutter_gallery/lib/demo/material/menu_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MenuDemoState extends State<MenuDemo> {
]
),
body: new ListView(
padding: const EdgeInsets.symmetric(vertical: 8.0),
padding: kMaterialListPadding,
children: <Widget>[
// Pressing the PopupMenuButton on the right of this item shows
// a simple menu with one disabled item. Typically the contents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class OverscrollDemoState extends State<OverscrollDemo> {
key: _refreshIndicatorKey,
onRefresh: _handleRefresh,
child: new ListView.builder(
padding: const EdgeInsets.all(8.0),
padding: kMaterialListPadding,
itemCount: _items.length,
itemBuilder: (BuildContext context, int index) {
final String item = _items[index];
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_gallery/lib/demo/shrine/shrine_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ShrinePageState extends State<ShrinePage> {
);
}
return new ListView(
padding: const EdgeInsets.symmetric(vertical: 8.0),
padding: kMaterialListPadding,
children: config.shoppingCart.values.map((Order order) {
return new ListTile(
title: new Text(order.product.name),
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter/lib/src/material/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/painting.dart';

/// The height of the toolbar component of the [AppBar].
const double kToolbarHeight = 56.0;

Expand All @@ -25,3 +27,5 @@ const int kRadialReactionAlpha = 0x33;

/// The duration
const Duration kTabScrollDuration = const Duration(milliseconds: 200);

const EdgeInsets kMaterialListPadding = const EdgeInsets.symmetric(vertical: 8.0);
8 changes: 4 additions & 4 deletions packages/flutter/lib/src/material/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';

import 'colors.dart';
import 'constants.dart';
import 'debug.dart';
import 'icon.dart';
import 'icons.dart';
Expand All @@ -21,7 +22,6 @@ import 'theme.dart';
const Duration _kDropdownMenuDuration = const Duration(milliseconds: 300);
const double _kMenuItemHeight = 48.0;
const double _kDenseButtonHeight = 24.0;
const EdgeInsets _kMenuVerticalPadding = const EdgeInsets.symmetric(vertical: 8.0);
const EdgeInsets _kMenuHorizontalPadding = const EdgeInsets.symmetric(horizontal: 16.0);

class _DropdownMenuPainter extends CustomPainter {
Expand Down Expand Up @@ -49,7 +49,7 @@ class _DropdownMenuPainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
final double selectedItemOffset = selectedIndex * _kMenuItemHeight + _kMenuVerticalPadding.top;
final double selectedItemOffset = selectedIndex * _kMenuItemHeight + kMaterialListPadding.top;
final Tween<double> top = new Tween<double>(
begin: selectedItemOffset.clamp(0.0, size.height - _kMenuItemHeight),
end: 0.0,
Expand Down Expand Up @@ -178,7 +178,7 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
child: new Scrollbar(
child: new ListView(
controller: config.route.scrollController,
padding: _kMenuVerticalPadding,
padding: kMaterialListPadding,
itemExtent: _kMenuItemHeight,
shrinkWrap: true,
children: children,
Expand Down Expand Up @@ -219,7 +219,7 @@ class _DropdownMenuRouteLayout<T> extends SingleChildLayoutDelegate {
@override
Offset getPositionForChild(Size size, Size childSize) {
final double buttonTop = buttonRect.top;
final double selectedItemOffset = selectedIndex * _kMenuItemHeight + _kMenuVerticalPadding.top;
final double selectedItemOffset = selectedIndex * _kMenuItemHeight + kMaterialListPadding.top;
double top = (buttonTop - selectedItemOffset) - (_kMenuItemHeight - buttonRect.height) / 2.0;
final double topPreferredLimit = _kMenuItemHeight;
if (top < topPreferredLimit)
Expand Down

0 comments on commit 269538d

Please sign in to comment.