From 5e9424419e3ce07890e8bf47b2f2a17f836113cf Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 3 Apr 2018 10:35:07 -0700 Subject: [PATCH] updated_card (#16187) --- .../lib/demo/material/cards_demo.dart | 38 +++++++++++++++-- packages/flutter/lib/src/material/card.dart | 41 ++++++++++++++----- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/examples/flutter_gallery/lib/demo/material/cards_demo.dart b/examples/flutter_gallery/lib/demo/material/cards_demo.dart index 831d1fa2dd..09435cf3bb 100644 --- a/examples/flutter_gallery/lib/demo/material/cards_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/cards_demo.dart @@ -47,12 +47,13 @@ final List destinations = [ ]; class TravelDestinationItem extends StatelessWidget { - TravelDestinationItem({ Key key, @required this.destination }) + TravelDestinationItem({ Key key, @required this.destination, this.shape }) : assert(destination != null && destination.isValid), super(key: key); static const double height = 366.0; final TravelDestination destination; + final ShapeBorder shape; @override Widget build(BuildContext context) { @@ -67,6 +68,7 @@ class TravelDestinationItem extends StatelessWidget { padding: const EdgeInsets.all(8.0), height: height, child: new Card( + shape: shape, child: new Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -149,14 +151,39 @@ class TravelDestinationItem extends StatelessWidget { } } -class CardsDemo extends StatelessWidget { + +class CardsDemo extends StatefulWidget { static const String routeName = '/material/cards'; + @override + _CardsDemoState createState() => new _CardsDemoState(); +} + +class _CardsDemoState extends State { + ShapeBorder _shape; + @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( - title: const Text('Travel stream') + title: const Text('Travel stream'), + actions: [ + new IconButton( + icon: const Icon(Icons.sentiment_very_satisfied), + onPressed: () { + setState(() { + _shape = _shape != null ? null : const RoundedRectangleBorder( + borderRadius: const BorderRadius.only( + topLeft: const Radius.circular(16.0), + topRight: const Radius.circular(16.0), + bottomLeft: const Radius.circular(2.0), + bottomRight: const Radius.circular(2.0), + ), + ); + }); + }, + ), + ], ), body: new ListView( itemExtent: TravelDestinationItem.height, @@ -164,7 +191,10 @@ class CardsDemo extends StatelessWidget { children: destinations.map((TravelDestination destination) { return new Container( margin: const EdgeInsets.only(bottom: 8.0), - child: new TravelDestinationItem(destination: destination) + child: new TravelDestinationItem( + destination: destination, + shape: _shape, + ), ); }).toList() ) diff --git a/packages/flutter/lib/src/material/card.dart b/packages/flutter/lib/src/material/card.dart index a4ce73a4bb..12940a888e 100644 --- a/packages/flutter/lib/src/material/card.dart +++ b/packages/flutter/lib/src/material/card.dart @@ -5,6 +5,7 @@ import 'package:flutter/widgets.dart'; import 'material.dart'; +import 'theme.dart'; /// A material design card. A card has slightly rounded corners and a shadow. /// @@ -62,24 +63,39 @@ class Card extends StatelessWidget { const Card({ Key key, this.color, - this.elevation: 2.0, + this.elevation, + this.shape, this.child, }) : super(key: key); - /// The widget below this widget in the tree. + /// The card's background color. /// - /// {@macro flutter.widgets.child} - final Widget child; - - /// The color of material used for this card. + /// Defines the card's [Material.color]. + /// + /// The default color is defined by the ambient [Theme]: [ThemeData.cardColor]. final Color color; /// The z-coordinate at which to place this card. This controls the size of /// the shadow below the card. /// - /// Defaults to 2, the appropriate elevation for cards. + /// Defines the card's [Material.elevation]. + /// + /// The default elevation is 1.0. final double elevation; + /// The shape of the card's [Material]. + /// + /// Defines the card's [Material.shape]. + /// + /// The default shape is a [RoundedRectangleBorder] with a circular corner + /// radius of 4.0. + final ShapeBorder shape; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.child} + final Widget child; + @override Widget build(BuildContext context) { return new Semantics( @@ -87,11 +103,14 @@ class Card extends StatelessWidget { child: new Container( margin: const EdgeInsets.all(4.0), child: new Material( - color: color, type: MaterialType.card, - elevation: elevation, - child: child - ) + color: color ?? Theme.of(context).cardColor, + elevation: elevation ?? 1.0, + shape: shape ?? const RoundedRectangleBorder( + borderRadius: const BorderRadius.all(const Radius.circular(4.0)), + ), + child: child, + ), ), ); }