1// Copyright 2015 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5import 'package:flutter/material.dart'; 6 7import '../../gallery/demo.dart'; 8 9class _PageSelector extends StatelessWidget { 10 const _PageSelector({ this.icons }); 11 12 final List<Icon> icons; 13 14 void _handleArrowButtonPress(BuildContext context, int delta) { 15 final TabController controller = DefaultTabController.of(context); 16 if (!controller.indexIsChanging) 17 controller.animateTo((controller.index + delta).clamp(0, icons.length - 1)); 18 } 19 20 @override 21 Widget build(BuildContext context) { 22 final TabController controller = DefaultTabController.of(context); 23 final Color color = Theme.of(context).accentColor; 24 return SafeArea( 25 top: false, 26 bottom: false, 27 child: Column( 28 children: <Widget>[ 29 Container( 30 margin: const EdgeInsets.only(top: 16.0), 31 child: Row( 32 children: <Widget>[ 33 IconButton( 34 icon: const Icon(Icons.chevron_left), 35 color: color, 36 onPressed: () { _handleArrowButtonPress(context, -1); }, 37 tooltip: 'Page back', 38 ), 39 TabPageSelector(controller: controller), 40 IconButton( 41 icon: const Icon(Icons.chevron_right), 42 color: color, 43 onPressed: () { _handleArrowButtonPress(context, 1); }, 44 tooltip: 'Page forward', 45 ), 46 ], 47 mainAxisAlignment: MainAxisAlignment.spaceBetween, 48 ), 49 ), 50 Expanded( 51 child: IconTheme( 52 data: IconThemeData( 53 size: 128.0, 54 color: color, 55 ), 56 child: TabBarView( 57 children: icons.map<Widget>((Icon icon) { 58 return Container( 59 padding: const EdgeInsets.all(12.0), 60 child: Card( 61 child: Center( 62 child: icon, 63 ), 64 ), 65 ); 66 }).toList(), 67 ), 68 ), 69 ), 70 ], 71 ), 72 ); 73 } 74} 75 76class PageSelectorDemo extends StatelessWidget { 77 static const String routeName = '/material/page-selector'; 78 static final List<Icon> icons = <Icon>[ 79 const Icon(Icons.event, semanticLabel: 'Event'), 80 const Icon(Icons.home, semanticLabel: 'Home'), 81 const Icon(Icons.android, semanticLabel: 'Android'), 82 const Icon(Icons.alarm, semanticLabel: 'Alarm'), 83 const Icon(Icons.face, semanticLabel: 'Face'), 84 const Icon(Icons.language, semanticLabel: 'Language'), 85 ]; 86 87 @override 88 Widget build(BuildContext context) { 89 return Scaffold( 90 appBar: AppBar( 91 title: const Text('Page selector'), 92 actions: <Widget>[MaterialDemoDocumentationButton(routeName)], 93 ), 94 body: DefaultTabController( 95 length: icons.length, 96 child: _PageSelector(icons: icons), 97 ), 98 ); 99 } 100} 101