Commit bf0f38c6 authored by Adam Barth's avatar Adam Barth

Add more dartdoc to material.dart (#3702)

This patch completes the circuit on this library. The next step is to go
through and add docs to anything we missed.
parent 50626e9b
...@@ -18,6 +18,7 @@ import 'theme.dart'; ...@@ -18,6 +18,7 @@ import 'theme.dart';
/// See also: /// See also:
/// ///
/// * [ListItem.divideItems] /// * [ListItem.divideItems]
/// * [PopupMenuDivider]
/// * <https://www.google.com/design/spec/components/dividers.html> /// * <https://www.google.com/design/spec/components/dividers.html>
class Divider extends StatelessWidget { class Divider extends StatelessWidget {
/// Creates a material design divider. /// Creates a material design divider.
......
...@@ -91,11 +91,25 @@ class _Painter extends CustomPainter { ...@@ -91,11 +91,25 @@ class _Painter extends CustomPainter {
/// If the OverscrollIndicator's child has more than one Scrollable descendant /// If the OverscrollIndicator's child has more than one Scrollable descendant
/// the scrollableKey parameter can be used to identify the one to track. /// the scrollableKey parameter can be used to identify the one to track.
class OverscrollIndicator extends StatefulWidget { class OverscrollIndicator extends StatefulWidget {
OverscrollIndicator({ Key key, this.scrollableKey, this.child }) : super(key: key) { /// Creates an overscroll indicator.
///
/// The [child] argument must not be null.
OverscrollIndicator({
Key key,
this.scrollableKey,
this.child
}) : super(key: key) {
assert(child != null); assert(child != null);
} }
/// Identifies the [Scrollable] descendant of child that the overscroll
/// indicator will track. Can be null if there's only one [Scrollable]
/// descendant.
final Key scrollableKey; final Key scrollableKey;
/// The overscroll indicator will be stacked on top of this child. The
/// indicator will appear when child's [Scrollable] descendant is
/// over-scrolled.
final Widget child; final Widget child;
@override @override
......
...@@ -39,9 +39,15 @@ class _MaterialPageTransition extends AnimatedWidget { ...@@ -39,9 +39,15 @@ class _MaterialPageTransition extends AnimatedWidget {
} }
} }
const Duration kMaterialPageRouteTransitionDuration = const Duration(milliseconds: 150); /// A modal route that replaces the entire screen with a material design transition.
///
/// The entrance transition for the page slides the page upwards and fades it
/// in. The exit transition is the same, but in reverse.
///
/// [MaterialApp] creates material page routes for entries in the
/// [MaterialApp.routes] map.
class MaterialPageRoute<T> extends PageRoute<T> { class MaterialPageRoute<T> extends PageRoute<T> {
/// Creates a page route for use in a material design app.
MaterialPageRoute({ MaterialPageRoute({
this.builder, this.builder,
Completer<T> completer, Completer<T> completer,
...@@ -51,10 +57,11 @@ class MaterialPageRoute<T> extends PageRoute<T> { ...@@ -51,10 +57,11 @@ class MaterialPageRoute<T> extends PageRoute<T> {
assert(opaque); assert(opaque);
} }
/// Builds the primary contents of the route.
final WidgetBuilder builder; final WidgetBuilder builder;
@override @override
Duration get transitionDuration => kMaterialPageRouteTransitionDuration; Duration get transitionDuration => const Duration(milliseconds: 150);
@override @override
Color get barrierColor => null; Color get barrierColor => null;
......
...@@ -29,20 +29,60 @@ const double _kMenuVerticalPadding = 8.0; ...@@ -29,20 +29,60 @@ const double _kMenuVerticalPadding = 8.0;
const double _kMenuWidthStep = 56.0; const double _kMenuWidthStep = 56.0;
const double _kMenuScreenPadding = 8.0; const double _kMenuScreenPadding = 8.0;
/// A base class for entries in a material design popup menu.
///
/// The popup menu widget uses this interface to interact with the menu items.
/// To show a popup menu, use the [showMenu] function. To create a button that
/// shows a popup menu, consider using [PopupMenuButton].
///
/// The type `T` is the type of the value the entry represents. All the entries
/// in a given menu must represent values with consistent types.
///
/// See also:
///
/// * [PopupMenuItem]
/// * [PopupMenuDivider]
/// * [CheckedPopupMenuItem]
/// * [showMenu]
/// * [PopupMenuButton]
abstract class PopupMenuEntry<T> extends StatefulWidget { abstract class PopupMenuEntry<T> extends StatefulWidget {
PopupMenuEntry({ Key key }) : super(key: key); /// Abstract const constructor. This constructor enables subclasses to provide
/// const constructors so that they can be used in const expressions.
const PopupMenuEntry({ Key key }) : super(key: key);
/// The amount of vertical space occupied by this entry.
///
/// This value must remain constant for a given instance.
double get height; double get height;
/// The value that should be returned by [showMenu] when the user selects this entry.
T get value => null; T get value => null;
bool get enabled => true;
/// Whether the user is permitted to select this entry.
bool get enabled;
} }
/// A horizontal divider in a material design popup menu.
///
/// This widget adatps the [Divider] for use in popup menus.
///
/// See also:
///
/// * [PopupMenuItem]
/// * [showMenu]
/// * [PopupMenuButton]
class PopupMenuDivider extends PopupMenuEntry<dynamic> { class PopupMenuDivider extends PopupMenuEntry<dynamic> {
/// Creates a horizontal divider for a popup menu.
///
/// By default, the divider has a height of 16.0 logical pixels.
PopupMenuDivider({ Key key, this.height: 16.0 }) : super(key: key); PopupMenuDivider({ Key key, this.height: 16.0 }) : super(key: key);
@override @override
final double height; final double height;
@override
bool get enabled => false;
@override @override
_PopupMenuDividerState createState() => new _PopupMenuDividerState(); _PopupMenuDividerState createState() => new _PopupMenuDividerState();
} }
...@@ -52,7 +92,24 @@ class _PopupMenuDividerState extends State<PopupMenuDivider> { ...@@ -52,7 +92,24 @@ class _PopupMenuDividerState extends State<PopupMenuDivider> {
Widget build(BuildContext context) => new Divider(height: config.height); Widget build(BuildContext context) => new Divider(height: config.height);
} }
/// An item in a material design popup menu.
///
/// To show a popup menu, use the [showMenu] function. To create a button that
/// shows a popup menu, consider using [PopupMenuButton].
///
/// To show a checkmark next to a popup menu item, consider using
/// [CheckedPopupMenuItem].
///
/// See also:
///
/// * [PopupMenuDivider]
/// * [CheckedPopupMenuItem]
/// * [showMenu]
/// * [PopupMenuButton]
class PopupMenuItem<T> extends PopupMenuEntry<T> { class PopupMenuItem<T> extends PopupMenuEntry<T> {
/// Creates an item for a popup menu.
///
/// By default, the item is enabled.
PopupMenuItem({ PopupMenuItem({
Key key, Key key,
this.value, this.value,
...@@ -121,7 +178,22 @@ class _PopupMenuItemState<T extends PopupMenuItem<dynamic>> extends State<T> { ...@@ -121,7 +178,22 @@ class _PopupMenuItemState<T extends PopupMenuItem<dynamic>> extends State<T> {
} }
} }
/// An item with a checkmark in a material design popup menu.
///
/// To show a popup menu, use the [showMenu] function. To create a button that
/// shows a popup menu, consider using [PopupMenuButton].
///
/// See also:
///
/// * [PopupMenuItem]
/// * [PopupMenuDivider]
/// * [CheckedPopupMenuItem]
/// * [showMenu]
/// * [PopupMenuButton]
class CheckedPopupMenuItem<T> extends PopupMenuItem<T> { class CheckedPopupMenuItem<T> extends PopupMenuItem<T> {
/// Creates a popup menu item with a checkmark.
///
/// By default, the menu item is enabled but unchecked.
CheckedPopupMenuItem({ CheckedPopupMenuItem({
Key key, Key key,
T value, T value,
...@@ -135,6 +207,7 @@ class CheckedPopupMenuItem<T> extends PopupMenuItem<T> { ...@@ -135,6 +207,7 @@ class CheckedPopupMenuItem<T> extends PopupMenuItem<T> {
child: child child: child
); );
/// Whether to display a checkmark next to the menu item.
final bool checked; final bool checked;
@override @override
...@@ -407,8 +480,10 @@ class PopupMenuButton<T> extends StatefulWidget { ...@@ -407,8 +480,10 @@ class PopupMenuButton<T> extends StatefulWidget {
/// Called when the button is pressed to create the items to show in the menu. /// Called when the button is pressed to create the items to show in the menu.
final PopupMenuItemBuilder<T> itemBuilder; final PopupMenuItemBuilder<T> itemBuilder;
/// The value of the menu item, if any, that should be highlighted when the menu opens.
final T initialValue; final T initialValue;
/// Called when the user selects a value from the popup menu created by this button.
final PopupMenuItemSelected<T> onSelected; final PopupMenuItemSelected<T> onSelected;
/// Text that describes the action that will occur when the button is pressed. /// Text that describes the action that will occur when the button is pressed.
......
...@@ -52,6 +52,10 @@ enum RefreshIndicatorLocation { top, bottom } ...@@ -52,6 +52,10 @@ enum RefreshIndicatorLocation { top, bottom }
/// ///
/// * <https://www.google.com/design/spec/patterns/swipe-to-refresh.html> /// * <https://www.google.com/design/spec/patterns/swipe-to-refresh.html>
class RefreshIndicator extends StatefulWidget { class RefreshIndicator extends StatefulWidget {
/// Creates a refresh indicator.
///
/// The [refresh] and [child] arguments must be non-null. The default
/// [displacement] is 40.0 logical pixels.
RefreshIndicator({ RefreshIndicator({
Key key, Key key,
this.scrollableKey, this.scrollableKey,
...@@ -65,7 +69,7 @@ class RefreshIndicator extends StatefulWidget { ...@@ -65,7 +69,7 @@ class RefreshIndicator extends StatefulWidget {
/// Identifies the [Scrollable] descendant of child that will cause the /// Identifies the [Scrollable] descendant of child that will cause the
/// refresh indicator to appear. Can be null if there's only one /// refresh indicator to appear. Can be null if there's only one
/// Scrollable descendant. /// [Scrollable] descendant.
final Key scrollableKey; final Key scrollableKey;
/// The distance from the child's top or bottom edge to where the refresh indicator /// The distance from the child's top or bottom edge to where the refresh indicator
...@@ -73,7 +77,6 @@ class RefreshIndicator extends StatefulWidget { ...@@ -73,7 +77,6 @@ class RefreshIndicator extends StatefulWidget {
/// displacement may significantly exceed this value. /// displacement may significantly exceed this value.
final double displacement; final double displacement;
/// A function that's called when the user has dragged the refresh indicator /// A function that's called when the user has dragged the refresh indicator
/// far enough to demonstrate that they want the app to refresh. The returned /// far enough to demonstrate that they want the app to refresh. The returned
/// Future must complete when the refresh operation is finished. /// Future must complete when the refresh operation is finished.
......
...@@ -76,11 +76,19 @@ class _Painter extends CustomPainter { ...@@ -76,11 +76,19 @@ class _Painter extends CustomPainter {
/// the scrollableKey parameter can be used to identify the one the Scrollbar /// the scrollableKey parameter can be used to identify the one the Scrollbar
/// should track. /// should track.
class Scrollbar extends StatefulWidget { class Scrollbar extends StatefulWidget {
/// Creates a scrollbar.
///
/// The child argument must not be null.
Scrollbar({ Key key, this.scrollableKey, this.child }) : super(key: key) { Scrollbar({ Key key, this.scrollableKey, this.child }) : super(key: key) {
assert(child != null); assert(child != null);
} }
/// Identifies the [Scrollable] descendant of child that the scrollbar will
/// track. Can be null if there's only one [Scrollable] descendant.
final Key scrollableKey; final Key scrollableKey;
/// The scrollbar will be stacked on top of this child. The scrollbar will
/// display when child's [Scrollable] descendant is scrolled.
final Widget child; final Widget child;
@override @override
...@@ -167,4 +175,4 @@ class _ScrollbarState extends State<Scrollbar> { ...@@ -167,4 +175,4 @@ class _ScrollbarState extends State<Scrollbar> {
) )
); );
} }
} }
\ No newline at end of file
...@@ -43,6 +43,9 @@ const Curve _snackBarFadeCurve = const Interval(0.72, 1.0, curve: Curves.fastOut ...@@ -43,6 +43,9 @@ const Curve _snackBarFadeCurve = const Interval(0.72, 1.0, curve: Curves.fastOut
/// * [SnackBar] /// * [SnackBar]
/// * <https://www.google.com/design/spec/components/snackbars-toasts.html> /// * <https://www.google.com/design/spec/components/snackbars-toasts.html>
class SnackBarAction extends StatefulWidget { class SnackBarAction extends StatefulWidget {
/// Creates an action for a [SnackBar].
///
/// The [label] and [onPressed] arguments must be non-null.
SnackBarAction({Key key, this.label, this.onPressed }) : super(key: key) { SnackBarAction({Key key, this.label, this.onPressed }) : super(key: key) {
assert(label != null); assert(label != null);
assert(onPressed != null); assert(onPressed != null);
...@@ -97,6 +100,9 @@ class _SnackBarActionState extends State<SnackBarAction> { ...@@ -97,6 +100,9 @@ class _SnackBarActionState extends State<SnackBarAction> {
/// * [SnackBarAction] /// * [SnackBarAction]
/// * <https://www.google.com/design/spec/components/snackbars-toasts.html> /// * <https://www.google.com/design/spec/components/snackbars-toasts.html>
class SnackBar extends StatelessWidget { class SnackBar extends StatelessWidget {
/// Creates a snack bar.
///
/// The [content] argument must be non-null.
SnackBar({ SnackBar({
Key key, Key key,
this.content, this.content,
...@@ -107,9 +113,21 @@ class SnackBar extends StatelessWidget { ...@@ -107,9 +113,21 @@ class SnackBar extends StatelessWidget {
assert(content != null); assert(content != null);
} }
/// The primary content of the snack bar.
///
/// Typically a [Text] widget.
final Widget content; final Widget content;
/// (optional) An action that the user can take based on the snack bar.
///
/// For example, the snack bar might let the user undo the operation that
/// prompted the snackbar. Snack bars can have at most one action.
final SnackBarAction action; final SnackBarAction action;
/// The amount of time the snack bar should be displayed.
final Duration duration; final Duration duration;
/// The animation driving the entrance and exit of the snack bar.
final Animation<double> animation; final Animation<double> animation;
@override @override
...@@ -180,6 +198,7 @@ class SnackBar extends StatelessWidget { ...@@ -180,6 +198,7 @@ class SnackBar extends StatelessWidget {
// API for Scaffold.addSnackBar(): // API for Scaffold.addSnackBar():
/// Creates an animation controller useful for driving a snack bar's entrance and exit animation.
static AnimationController createAnimationController() { static AnimationController createAnimationController() {
return new AnimationController( return new AnimationController(
duration: _kSnackBarTransitionDuration, duration: _kSnackBarTransitionDuration,
...@@ -187,6 +206,10 @@ class SnackBar extends StatelessWidget { ...@@ -187,6 +206,10 @@ class SnackBar extends StatelessWidget {
); );
} }
/// Creates a copy of this snack bar but with the animation replaced with the given animation.
///
/// If the original snack bar lacks a key, the newly created snack bar will
/// use the given fallback key.
SnackBar withAnimation(Animation<double> newAnimation, { Key fallbackKey }) { SnackBar withAnimation(Animation<double> newAnimation, { Key fallbackKey }) {
return new SnackBar( return new SnackBar(
key: key ?? fallbackKey, key: key ?? fallbackKey,
......
...@@ -34,7 +34,7 @@ class TestRoute<T> extends PageRoute<T> { ...@@ -34,7 +34,7 @@ class TestRoute<T> extends PageRoute<T> {
final Widget child; final Widget child;
@override @override
Duration get transitionDuration => kMaterialPageRouteTransitionDuration; Duration get transitionDuration => const Duration(milliseconds: 150);
@override @override
Color get barrierColor => null; Color get barrierColor => null;
...@@ -46,8 +46,8 @@ class TestRoute<T> extends PageRoute<T> { ...@@ -46,8 +46,8 @@ class TestRoute<T> extends PageRoute<T> {
} }
void main() { void main() {
final Duration kTwoTenthsOfTheTransitionDuration = kMaterialPageRouteTransitionDuration * 0.2; final Duration kTwoTenthsOfTheTransitionDuration = const Duration(milliseconds: 30);
final Duration kFourTenthsOfTheTransitionDuration = kMaterialPageRouteTransitionDuration * 0.4; final Duration kFourTenthsOfTheTransitionDuration = const Duration(milliseconds: 60);
testWidgets('Check onstage/offstage handling around transitions', (WidgetTester tester) { testWidgets('Check onstage/offstage handling around transitions', (WidgetTester tester) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment