From 07eb5ea0beae1bc90309426ad3d2adb8f9e22415 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Mon, 12 Mar 2018 12:20:33 -0700 Subject: [PATCH] Added custom selection indicators to the gallery scrollable tabs demo (#15323) --- .../demo/material/scrollable_tabs_demo.dart | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/examples/flutter_gallery/lib/demo/material/scrollable_tabs_demo.dart b/examples/flutter_gallery/lib/demo/material/scrollable_tabs_demo.dart index f2534de928..45e82acc58 100644 --- a/examples/flutter_gallery/lib/demo/material/scrollable_tabs_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/scrollable_tabs_demo.dart @@ -43,6 +43,7 @@ class ScrollableTabsDemo extends StatefulWidget { class ScrollableTabsDemoState extends State with SingleTickerProviderStateMixin { TabController _controller; TabsDemoStyle _demoStyle = TabsDemoStyle.iconsAndText; + bool _customIndicator = false; @override void initState() { @@ -62,6 +63,61 @@ class ScrollableTabsDemoState extends State with SingleTicke }); } + ShapeDecoration getIndicator() { + if (!_customIndicator) + return null; + + switch(_demoStyle) { + case TabsDemoStyle.iconsAndText: + return new ShapeDecoration( + shape: const RoundedRectangleBorder( + borderRadius: const BorderRadius.all(const Radius.circular(4.0)), + side: const BorderSide( + color: Colors.white24, + width: 2.0, + ), + ) + const RoundedRectangleBorder( + borderRadius: const BorderRadius.all(const Radius.circular(4.0)), + side: const BorderSide( + color: Colors.transparent, + width: 4.0, + ), + ), + ); + + case TabsDemoStyle.iconsOnly: + return new ShapeDecoration( + shape: const CircleBorder( + side: const BorderSide( + color: Colors.white24, + width: 4.0, + ), + ) + const CircleBorder( + side: const BorderSide( + color: Colors.transparent, + width: 4.0, + ), + ), + ); + + case TabsDemoStyle.textOnly: + return new ShapeDecoration( + shape: const StadiumBorder( + side: const BorderSide( + color: Colors.white24, + width: 2.0, + ), + ) + const StadiumBorder( + side: const BorderSide( + color: Colors.transparent, + width: 4.0, + ), + ), + ); + } + return null; + } + @override Widget build(BuildContext context) { final Color iconColor = Theme.of(context).accentColor; @@ -69,6 +125,14 @@ class ScrollableTabsDemoState extends State with SingleTicke appBar: new AppBar( title: const Text('Scrollable tabs'), actions: [ + new IconButton( + icon: const Icon(Icons.sentiment_very_satisfied), + onPressed: () { + setState(() { + _customIndicator = !_customIndicator; + }); + }, + ), new PopupMenuButton( onSelected: changeDemoStyle, itemBuilder: (BuildContext context) => >[ @@ -90,6 +154,7 @@ class ScrollableTabsDemoState extends State with SingleTicke bottom: new TabBar( controller: _controller, isScrollable: true, + indicator: getIndicator(), tabs: _allPages.map((_Page page) { switch (_demoStyle) { case TabsDemoStyle.iconsAndText: