Unverified Commit 07eb5ea0 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Added custom selection indicators to the gallery scrollable tabs demo (#15323)

parent a6159279
...@@ -43,6 +43,7 @@ class ScrollableTabsDemo extends StatefulWidget { ...@@ -43,6 +43,7 @@ class ScrollableTabsDemo extends StatefulWidget {
class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTickerProviderStateMixin { class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTickerProviderStateMixin {
TabController _controller; TabController _controller;
TabsDemoStyle _demoStyle = TabsDemoStyle.iconsAndText; TabsDemoStyle _demoStyle = TabsDemoStyle.iconsAndText;
bool _customIndicator = false;
@override @override
void initState() { void initState() {
...@@ -62,6 +63,61 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke ...@@ -62,6 +63,61 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Color iconColor = Theme.of(context).accentColor; final Color iconColor = Theme.of(context).accentColor;
...@@ -69,6 +125,14 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke ...@@ -69,6 +125,14 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
appBar: new AppBar( appBar: new AppBar(
title: const Text('Scrollable tabs'), title: const Text('Scrollable tabs'),
actions: <Widget>[ actions: <Widget>[
new IconButton(
icon: const Icon(Icons.sentiment_very_satisfied),
onPressed: () {
setState(() {
_customIndicator = !_customIndicator;
});
},
),
new PopupMenuButton<TabsDemoStyle>( new PopupMenuButton<TabsDemoStyle>(
onSelected: changeDemoStyle, onSelected: changeDemoStyle,
itemBuilder: (BuildContext context) => <PopupMenuItem<TabsDemoStyle>>[ itemBuilder: (BuildContext context) => <PopupMenuItem<TabsDemoStyle>>[
...@@ -90,6 +154,7 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke ...@@ -90,6 +154,7 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
bottom: new TabBar( bottom: new TabBar(
controller: _controller, controller: _controller,
isScrollable: true, isScrollable: true,
indicator: getIndicator(),
tabs: _allPages.map((_Page page) { tabs: _allPages.map((_Page page) {
switch (_demoStyle) { switch (_demoStyle) {
case TabsDemoStyle.iconsAndText: case TabsDemoStyle.iconsAndText:
......
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