From 9d49ee3bf06e634e53331b544dbb640453f81348 Mon Sep 17 00:00:00 2001 From: Natalie Sampsell Date: Tue, 10 Jul 2018 11:17:47 -0700 Subject: [PATCH] Add segmented control to gallery (#19192) * Adding segmented control to gallery --- .../lib/demo/cupertino/cupertino.dart | 1 + .../cupertino_segmented_control_demo.dart | 117 ++++++++++++++++++ .../flutter_gallery/lib/gallery/demos.dart | 7 ++ 3 files changed, 125 insertions(+) create mode 100644 examples/flutter_gallery/lib/demo/cupertino/cupertino_segmented_control_demo.dart diff --git a/examples/flutter_gallery/lib/demo/cupertino/cupertino.dart b/examples/flutter_gallery/lib/demo/cupertino/cupertino.dart index da10d71342..641c168994 100644 --- a/examples/flutter_gallery/lib/demo/cupertino/cupertino.dart +++ b/examples/flutter_gallery/lib/demo/cupertino/cupertino.dart @@ -8,5 +8,6 @@ export 'cupertino_dialog_demo.dart'; export 'cupertino_navigation_demo.dart'; export 'cupertino_picker_demo.dart'; export 'cupertino_refresh_demo.dart'; +export 'cupertino_segmented_control_demo.dart'; export 'cupertino_slider_demo.dart'; export 'cupertino_switch_demo.dart'; diff --git a/examples/flutter_gallery/lib/demo/cupertino/cupertino_segmented_control_demo.dart b/examples/flutter_gallery/lib/demo/cupertino/cupertino_segmented_control_demo.dart new file mode 100644 index 0000000000..0fc0d26b37 --- /dev/null +++ b/examples/flutter_gallery/lib/demo/cupertino/cupertino_segmented_control_demo.dart @@ -0,0 +1,117 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +const Color _kKeyUmbraOpacity = const Color(0x33000000); // alpha = 0.2 +const Color _kKeyPenumbraOpacity = const Color(0x24000000); // alpha = 0.14 +const Color _kAmbientShadowOpacity = const Color(0x1F000000); // alpha = 0.12 + +class CupertinoSegmentedControlDemo extends StatefulWidget { + static const String routeName = 'cupertino/segmented_control'; + + @override + _CupertinoSegmentedControlDemoState createState() => new _CupertinoSegmentedControlDemoState(); +} + +class _CupertinoSegmentedControlDemoState extends State { + final Map children = const { + 0: Center( + child: const Text('Midnight'), + ), + 1: Center( + child: const Text('Viridian'), + ), + 2: Center( + child: const Text('Cerulean'), + ), + }; + + final Map icons = const { + 0: Center( + child: const FlutterLogo( + colors: Colors.indigo, + size: 200.0, + ), + ), + 1: Center( + child: const FlutterLogo( + colors: Colors.teal, + size: 200.0, + ), + ), + 2: Center( + child: const FlutterLogo( + colors: Colors.cyan, + size: 200.0, + ), + ), + }; + + int sharedValue = 0; + + @override + Widget build(BuildContext context) { + return new Scaffold( + appBar: new AppBar( + title: const Text('Cupertino Segmented Control'), + ), + body: new Column( + children: [ + const Padding( + padding: const EdgeInsets.all(16.0), + ), + new SegmentedControl( + children: children, + onValueChanged: (int newValue) { + setState(() { + sharedValue = newValue; + }); + }, + groupValue: sharedValue, + ), + new Expanded( + child: new Padding( + padding: const EdgeInsets.symmetric( + vertical: 32.0, + horizontal: 16.0, + ), + child: new Container( + padding: const EdgeInsets.symmetric( + vertical: 64.0, + horizontal: 16.0, + ), + decoration: new BoxDecoration( + color: CupertinoColors.white, + borderRadius: new BorderRadius.circular(3.0), + boxShadow: const [ + const BoxShadow( + offset: const Offset(0.0, 3.0), + blurRadius: 5.0, + spreadRadius: -1.0, + color: _kKeyUmbraOpacity, + ), + const BoxShadow( + offset: const Offset(0.0, 6.0), + blurRadius: 10.0, + spreadRadius: 0.0, + color: _kKeyPenumbraOpacity, + ), + const BoxShadow( + offset: const Offset(0.0, 1.0), + blurRadius: 18.0, + spreadRadius: 0.0, + color: _kAmbientShadowOpacity, + ), + ], + ), + child: icons[sharedValue]), + ), + ), + ], + ), + ); + } +} diff --git a/examples/flutter_gallery/lib/gallery/demos.dart b/examples/flutter_gallery/lib/gallery/demos.dart index 375241de3e..4f1fb5652c 100644 --- a/examples/flutter_gallery/lib/gallery/demos.dart +++ b/examples/flutter_gallery/lib/gallery/demos.dart @@ -421,6 +421,13 @@ List _buildGalleryDemos() { routeName: CupertinoRefreshControlDemo.routeName, buildRoute: (BuildContext context) => new CupertinoRefreshControlDemo(), ), + new GalleryDemo( + title: 'Segmented Control', + icon: GalleryIcons.tabs, + category: _kCupertinoComponents, + routeName: CupertinoSegmentedControlDemo.routeName, + buildRoute: (BuildContext context) => new CupertinoSegmentedControlDemo(), + ), new GalleryDemo( title: 'Sliders', icon: GalleryIcons.sliders,