mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
* update gallery and web samples compatable with SDK version 2a576b774c: Flutter 1.12.3-pre.38 • channel master • git@github.com:flutter/flutter.git Framework • revision 2a576b774c (2 hours ago) • 2019-11-15 13:15:05 -0800 Engine • revision b2640d97e7 Tools • Dart 2.7.0 * add preview image
146 lines
4.9 KiB
Dart
146 lines
4.9 KiB
Dart
// 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';
|
|
|
|
import '../../gallery/demo.dart';
|
|
|
|
const Color _kKeyUmbraOpacity = Color(0x33000000); // alpha = 0.2
|
|
const Color _kKeyPenumbraOpacity = Color(0x24000000); // alpha = 0.14
|
|
const Color _kAmbientShadowOpacity = Color(0x1F000000); // alpha = 0.12
|
|
|
|
class CupertinoSegmentedControlDemo extends StatefulWidget {
|
|
static const String routeName = 'cupertino/segmented_control';
|
|
|
|
@override
|
|
_CupertinoSegmentedControlDemoState createState() => _CupertinoSegmentedControlDemoState();
|
|
}
|
|
|
|
class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedControlDemo> {
|
|
final Map<int, Widget> children = const <int, Widget>{
|
|
0: Text('Midnight'),
|
|
1: Text('Viridian'),
|
|
2: Text('Cerulean'),
|
|
};
|
|
|
|
final Map<int, Widget> icons = const <int, Widget>{
|
|
0: Center(
|
|
child: FlutterLogo(
|
|
colors: Colors.indigo,
|
|
size: 200.0,
|
|
),
|
|
),
|
|
1: Center(
|
|
child: FlutterLogo(
|
|
colors: Colors.teal,
|
|
size: 200.0,
|
|
),
|
|
),
|
|
2: Center(
|
|
child: FlutterLogo(
|
|
colors: Colors.cyan,
|
|
size: 200.0,
|
|
),
|
|
),
|
|
};
|
|
|
|
int currentSegment = 0;
|
|
|
|
void onValueChanged(int newValue) {
|
|
setState(() {
|
|
currentSegment = newValue;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: CupertinoNavigationBar(
|
|
middle: const Text('Segmented Control'),
|
|
// We're specifying a back label here because the previous page is a
|
|
// Material page. CupertinoPageRoutes could auto-populate these back
|
|
// labels.
|
|
previousPageTitle: 'Cupertino',
|
|
trailing: CupertinoDemoDocumentationButton(CupertinoSegmentedControlDemo.routeName),
|
|
),
|
|
child: DefaultTextStyle(
|
|
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(fontSize: 13),
|
|
child: SafeArea(
|
|
child: Column(
|
|
children: <Widget>[
|
|
const Padding(padding: EdgeInsets.all(16.0)),
|
|
SizedBox(
|
|
width: 500.0,
|
|
child: CupertinoSegmentedControl<int>(
|
|
children: children,
|
|
onValueChanged: onValueChanged,
|
|
groupValue: currentSegment,
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 500,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: CupertinoSlidingSegmentedControl<int>(
|
|
children: children,
|
|
onValueChanged: onValueChanged,
|
|
groupValue: currentSegment,
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 32.0,
|
|
horizontal: 16.0,
|
|
),
|
|
child: CupertinoUserInterfaceLevel(
|
|
data: CupertinoUserInterfaceLevelData.elevated,
|
|
child: Builder(
|
|
builder: (BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 64.0,
|
|
horizontal: 16.0,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: CupertinoTheme.of(context).scaffoldBackgroundColor,
|
|
borderRadius: BorderRadius.circular(3.0),
|
|
boxShadow: const <BoxShadow>[
|
|
BoxShadow(
|
|
offset: Offset(0.0, 3.0),
|
|
blurRadius: 5.0,
|
|
spreadRadius: -1.0,
|
|
color: _kKeyUmbraOpacity,
|
|
),
|
|
BoxShadow(
|
|
offset: Offset(0.0, 6.0),
|
|
blurRadius: 10.0,
|
|
spreadRadius: 0.0,
|
|
color: _kKeyPenumbraOpacity,
|
|
),
|
|
BoxShadow(
|
|
offset: Offset(0.0, 1.0),
|
|
blurRadius: 18.0,
|
|
spreadRadius: 0.0,
|
|
color: _kAmbientShadowOpacity,
|
|
),
|
|
],
|
|
),
|
|
child: icons[currentSegment],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|