Remove //examples/widgets

Most of the remaining widget examples are actually manual tests. This patch
moves them into //dev/manual_tests. A couple are examples of using services,
which I've moved to //examples/layers/services. The remainder are out-dated and
are removed by this patch.
This commit is contained in:
Adam Barth
2016-03-08 16:35:23 -08:00
parent efa36de7f0
commit e4b1eab854
25 changed files with 14 additions and 558 deletions

View File

@@ -15,6 +15,9 @@ Flutter's layered architecture.
* [*widgets/*](widgets/) These examples use Flutter's widgets to build more
elaborate apps using a reactive framework.
* [*services/*](services/) These examples use services available in Flutter to
interact with the host platform.
To run each example, use the `-t` argument to the `flutter` tool:
```

View File

@@ -1,10 +0,0 @@
Small examples of the Flutter widget framework
==============================================
To run these, open a terminal in this directory and use the following command:
```bash
flutter run -t foo.dart
```
...where `foo.dart` is the file you want to run.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -1,469 +0,0 @@
// Copyright 2015 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/material.dart';
import 'package:flutter/rendering.dart' show debugDumpRenderTree;
class CardModel {
CardModel(this.value, this.height) {
inputValue = new InputValue(text: "Item $value");
}
int value;
double height;
int get color => ((value % 9) + 1) * 100;
InputValue inputValue;
Key get key => new ObjectKey(this);
}
class CardCollection extends StatefulComponent {
CardCollectionState createState() => new CardCollectionState();
}
class CardCollectionState extends State<CardCollection> {
static const TextStyle cardLabelStyle =
const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold);
// TODO(hansmuller): need a local image asset
static const _sunshineURL = "http://www.walltor.com/images/wallpaper/good-morning-sunshine-58540.jpg";
static const kCardMargins = 8.0;
final TextStyle backgroundTextStyle =
Typography.white.title.copyWith(textAlign: TextAlign.center);
Map<int, Color> _primaryColor = Colors.deepPurple;
List<CardModel> _cardModels;
DismissDirection _dismissDirection = DismissDirection.horizontal;
TextStyle _textStyle = new TextStyle(textAlign: TextAlign.center);
bool _editable = false;
bool _snapToCenter = false;
bool _fixedSizeCards = false;
bool _sunshine = false;
bool _varyFontSizes = false;
InvalidatorCallback _invalidator;
void _initVariableSizedCardModels() {
List<double> cardHeights = <double>[
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0
];
_cardModels = new List<CardModel>.generate(
cardHeights.length,
(int i) => new CardModel(i, cardHeights[i])
);
}
void _initFixedSizedCardModels() {
const int cardCount = 27;
const double cardHeight = 100.0;
_cardModels = new List<CardModel>.generate(
cardCount,
(int i) => new CardModel(i, cardHeight)
);
}
void _initCardModels() {
if (_fixedSizeCards)
_initFixedSizedCardModels();
else
_initVariableSizedCardModels();
}
void initState() {
super.initState();
_initCardModels();
}
double _variableSizeToSnapOffset(double scrollOffset) {
double cumulativeHeight = 0.0;
List<double> cumulativeHeights = _cardModels.map((CardModel card) {
cumulativeHeight += card.height + kCardMargins;
return cumulativeHeight;
})
.toList();
double offsetForIndex(int i) {
return (kCardMargins + _cardModels[i].height) / 2.0 + ((i == 0) ? 0.0 : cumulativeHeights[i - 1]);
}
for (int i = 0; i < cumulativeHeights.length; i++) {
if (cumulativeHeights[i] >= scrollOffset)
return offsetForIndex(i);
}
return offsetForIndex(cumulativeHeights.length - 1);
}
double _fixedSizeToSnapOffset(double scrollOffset) {
double cardHeight = _cardModels[0].height;
int cardIndex = (scrollOffset.clamp(0.0, cardHeight * (_cardModels.length - 1)) / cardHeight).floor();
return cardIndex * cardHeight + cardHeight * 0.5;
}
double _toSnapOffset(double scrollOffset, Size containerSize) {
double halfHeight = containerSize.height / 2.0;
scrollOffset += halfHeight;
double result = _fixedSizeCards ? _fixedSizeToSnapOffset(scrollOffset) : _variableSizeToSnapOffset(scrollOffset);
return result - halfHeight;
}
void dismissCard(CardModel card) {
if (_cardModels.contains(card)) {
setState(() {
_cardModels.remove(card);
});
}
}
Widget _buildDrawer() {
return new Drawer(
child: new IconTheme(
data: const IconThemeData(color: Colors.black),
child: new Block(children: <Widget>[
new DrawerHeader(child: new Text('Options')),
buildDrawerCheckbox("Make card labels editable", _editable, _toggleEditable),
buildDrawerCheckbox("Snap fling scrolls to center", _snapToCenter, _toggleSnapToCenter),
buildDrawerCheckbox("Fixed size cards", _fixedSizeCards, _toggleFixedSizeCards),
buildDrawerCheckbox("Let the sun shine", _sunshine, _toggleSunshine),
buildDrawerCheckbox("Vary font sizes", _varyFontSizes, _toggleVaryFontSizes, enabled: !_editable),
new Divider(),
buildDrawerColorRadioItem("Deep Purple", Colors.deepPurple, _primaryColor, _selectColor),
buildDrawerColorRadioItem("Green", Colors.green, _primaryColor, _selectColor),
buildDrawerColorRadioItem("Amber", Colors.amber, _primaryColor, _selectColor),
buildDrawerColorRadioItem("Teal", Colors.teal, _primaryColor, _selectColor),
new Divider(),
buildDrawerDirectionRadioItem("Dismiss horizontally", DismissDirection.horizontal, _dismissDirection, _changeDismissDirection, icon: Icons.code),
buildDrawerDirectionRadioItem("Dismiss left", DismissDirection.left, _dismissDirection, _changeDismissDirection, icon: Icons.arrow_back),
buildDrawerDirectionRadioItem("Dismiss right", DismissDirection.right, _dismissDirection, _changeDismissDirection, icon: Icons.arrow_forward),
new Divider(),
buildFontRadioItem("Left-align text", new TextStyle(textAlign: TextAlign.left), _textStyle, _changeTextStyle, icon: Icons.format_align_left, enabled: !_editable),
buildFontRadioItem("Center-align text", new TextStyle(textAlign: TextAlign.center), _textStyle, _changeTextStyle, icon: Icons.format_align_center, enabled: !_editable),
buildFontRadioItem("Right-align text", new TextStyle(textAlign: TextAlign.right), _textStyle, _changeTextStyle, icon: Icons.format_align_right, enabled: !_editable),
new Divider(),
new DrawerItem(
icon: Icons.dvr,
onPressed: () { debugDumpApp(); debugDumpRenderTree(); },
child: new Text('Dump App to Console')
),
])
)
);
}
String _dismissDirectionText(DismissDirection direction) {
String s = direction.toString();
return "dismiss ${s.substring(s.indexOf('.') + 1)}";
}
void _toggleEditable() {
setState(() {
_editable = !_editable;
});
}
void _toggleFixedSizeCards() {
setState(() {
_fixedSizeCards = !_fixedSizeCards;
_initCardModels();
});
}
void _toggleSnapToCenter() {
setState(() {
_snapToCenter = !_snapToCenter;
});
}
void _toggleSunshine() {
setState(() {
_sunshine = !_sunshine;
});
}
void _toggleVaryFontSizes() {
setState(() {
_varyFontSizes = !_varyFontSizes;
});
}
void _selectColor(Map<int, Color> selection) {
setState(() {
_primaryColor = selection;
});
}
void _changeDismissDirection(DismissDirection newDismissDirection) {
setState(() {
_dismissDirection = newDismissDirection;
});
}
void _changeTextStyle(TextStyle newTextStyle) {
setState(() {
_textStyle = newTextStyle;
});
}
Widget buildDrawerCheckbox(String label, bool value, void callback(), { bool enabled: true }) {
return new DrawerItem(
onPressed: enabled ? callback : null,
child: new Row(
children: <Widget>[
new Flexible(child: new Text(label)),
new Checkbox(
value: value,
onChanged: enabled ? (_) { callback(); } : null
)
]
)
);
}
Widget buildDrawerColorRadioItem(String label, Map<int, Color> itemValue, Map<int, Color> currentValue, ValueChanged<Map<int, Color>> onChanged, { IconData icon, bool enabled: true }) {
return new DrawerItem(
icon: icon,
onPressed: enabled ? () { onChanged(itemValue); } : null,
child: new Row(
children: <Widget>[
new Flexible(child: new Text(label)),
new Radio<Map<int, Color>>(
value: itemValue,
groupValue: currentValue,
onChanged: enabled ? onChanged : null
)
]
)
);
}
Widget buildDrawerDirectionRadioItem(String label, DismissDirection itemValue, DismissDirection currentValue, ValueChanged<DismissDirection> onChanged, { IconData icon, bool enabled: true }) {
return new DrawerItem(
icon: icon,
onPressed: enabled ? () { onChanged(itemValue); } : null,
child: new Row(
children: <Widget>[
new Flexible(child: new Text(label)),
new Radio<DismissDirection>(
value: itemValue,
groupValue: currentValue,
onChanged: enabled ? onChanged : null
)
]
)
);
}
Widget buildFontRadioItem(String label, TextStyle itemValue, TextStyle currentValue, ValueChanged<TextStyle> onChanged, { IconData icon, bool enabled: true }) {
return new DrawerItem(
icon: icon,
onPressed: enabled ? () { onChanged(itemValue); } : null,
child: new Row(
children: <Widget>[
new Flexible(child: new Text(label)),
new Radio<TextStyle>(
value: itemValue,
groupValue: currentValue,
onChanged: enabled ? onChanged : null
)
]
)
);
}
Widget _buildToolBar(BuildContext context) {
return new ToolBar(
right: <Widget>[
new Text(_dismissDirectionText(_dismissDirection))
],
flexibleSpace: (_) {
return new Container(
padding: const EdgeDims.only(left: 72.0),
height: 128.0,
child: new Align(
alignment: const FractionalOffset(0.0, 0.75),
child: new Text('Swipe Away: ${_cardModels.length}', style: Theme.of(context).primaryTextTheme.title)
)
);
}
);
}
Widget _buildCard(BuildContext context, int index) {
if (index >= _cardModels.length)
return null;
CardModel cardModel = _cardModels[index];
Widget card = new Dismissable(
key: new ObjectKey(cardModel),
direction: _dismissDirection,
onResize: () { _invalidator(<int>[index]); },
onDismissed: (DismissDirection direction) { dismissCard(cardModel); },
child: new Card(
color: _primaryColor[cardModel.color],
child: new Container(
height: cardModel.height,
padding: const EdgeDims.all(kCardMargins),
child: _editable ?
new Center(
child: new Input(
key: new GlobalObjectKey(cardModel),
value: cardModel.inputValue,
onChanged: (InputValue value) {
setState(() {
cardModel.inputValue = value;
});
}
)
)
: new DefaultTextStyle(
style: DefaultTextStyle.of(context).merge(cardLabelStyle).merge(_textStyle).copyWith(
fontSize: _varyFontSizes ? _cardModels.length.toDouble() : null
),
child: new Column(
children: <Widget>[
new Text(cardModel.inputValue.text)
],
alignItems: FlexAlignItems.stretch,
justifyContent: FlexJustifyContent.center
)
)
)
)
);
String backgroundMessage;
switch(_dismissDirection) {
case DismissDirection.horizontal:
backgroundMessage = "Swipe in either direction";
break;
case DismissDirection.left:
backgroundMessage = "Swipe left to dismiss";
break;
case DismissDirection.right:
backgroundMessage = "Swipe right to dismiss";
break;
default:
backgroundMessage = "Unsupported dismissDirection";
}
Widget leftArrowIcon = new Icon(icon: Icons.arrow_back, size: 36.0);
if (_dismissDirection == DismissDirection.right)
leftArrowIcon = new Opacity(opacity: 0.1, child: leftArrowIcon);
Widget rightArrowIcon = new Icon(icon: Icons.arrow_forward, size: 36.0);
if (_dismissDirection == DismissDirection.left)
rightArrowIcon = new Opacity(opacity: 0.1, child: rightArrowIcon);
// The background Widget appears behind the Dismissable card when the card
// moves to the left or right. The Positioned widget ensures that the
// size of the background,card Stack will be based only on the card. The
// Viewport ensures that when the card's resize animation occurs, the
// background (text and icons) will just be clipped, not resized.
Widget background = new Positioned(
top: 0.0,
right: 0.0,
bottom: 0.0,
left: 0.0,
child: new Container(
margin: const EdgeDims.all(4.0),
child: new Viewport(
child: new Container(
height: cardModel.height,
decoration: new BoxDecoration(backgroundColor: Theme.of(context).primaryColor),
child: new Row(
children: <Widget>[
leftArrowIcon,
new Flexible(child: new Text(backgroundMessage, style: backgroundTextStyle)),
rightArrowIcon
]
)
)
)
)
);
return new IconTheme(
key: cardModel.key,
data: const IconThemeData(color: Colors.white),
child: new Stack(children: <Widget>[background, card])
);
}
Shader _createShader(Rect bounds) {
return new LinearGradient(
begin: const Offset(0.0, 0.0),
end: const Offset(0.0, 1.0),
colors: <Color>[const Color(0x00FFFFFF), const Color(0xFFFFFFFF)],
stops: <double>[0.1, 0.35]
)
.createShader(bounds);
}
Widget build(BuildContext context) {
Widget cardCollection;
if (_fixedSizeCards) {
cardCollection = new ScrollableList (
snapOffsetCallback: _snapToCenter ? _toSnapOffset : null,
itemExtent: _cardModels[0].height,
children: _cardModels.map((CardModel card) => _buildCard(context, card.value))
);
} else {
cardCollection = new ScrollableMixedWidgetList(
builder: _buildCard,
token: _cardModels.length,
snapOffsetCallback: _snapToCenter ? _toSnapOffset : null,
onInvalidatorAvailable: (InvalidatorCallback callback) { _invalidator = callback; }
);
}
if (_sunshine) {
cardCollection = new Stack(
children: <Widget>[
new Column(children: <Widget>[new NetworkImage(src: _sunshineURL)]),
new ShaderMask(child: cardCollection, shaderCallback: _createShader)
]
);
}
Widget body = new Container(
padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0),
decoration: new BoxDecoration(backgroundColor: _primaryColor[50]),
child: cardCollection
);
if (_snapToCenter) {
Widget indicator = new IgnorePointer(
child: new Align(
alignment: const FractionalOffset(0.0, 0.5),
child: new Container(
height: 1.0,
decoration: new BoxDecoration(backgroundColor: const Color(0x80FFFFFF))
)
)
);
body = new Stack(children: <Widget>[body, indicator]);
}
return new Theme(
data: new ThemeData(
primarySwatch: _primaryColor
),
child: new Scaffold(
toolBar: _buildToolBar(context),
drawer: _buildDrawer(),
body: body
)
);
}
}
void main() {
runApp(new MaterialApp(
title: 'Cards',
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new CardCollection(),
}
));
}

View File

@@ -1,290 +0,0 @@
// Copyright 2015 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 'dart:math' as math;
import 'package:flutter/material.dart';
class ExampleDragTarget extends StatefulComponent {
ExampleDragTargetState createState() => new ExampleDragTargetState();
}
class ExampleDragTargetState extends State<ExampleDragTarget> {
Color _color = Colors.grey[500];
void _handleAccept(Color data) {
setState(() {
_color = data;
});
}
Widget build(BuildContext context) {
return new DragTarget<Color>(
onAccept: _handleAccept,
builder: (BuildContext context, List<Color> data, List<Color> rejectedData) {
return new Container(
height: 100.0,
margin: new EdgeDims.all(10.0),
decoration: new BoxDecoration(
border: new Border.all(
width: 3.0,
color: data.isEmpty ? Colors.white : Colors.blue[500]
),
backgroundColor: data.isEmpty ? _color : Colors.grey[200]
)
);
}
);
}
}
class Dot extends StatefulComponent {
Dot({ Key key, this.color, this.size, this.child, this.tappable: false }) : super(key: key);
final Color color;
final double size;
final Widget child;
final bool tappable;
DotState createState() => new DotState();
}
class DotState extends State<Dot> {
int taps = 0;
Widget build(BuildContext context) {
return new GestureDetector(
onTap: config.tappable ? () { setState(() { taps += 1; }); } : null,
child: new Container(
width: config.size,
height: config.size,
decoration: new BoxDecoration(
backgroundColor: config.color,
border: new Border.all(color: const Color(0xFF000000), width: taps.toDouble()),
shape: BoxShape.circle
),
child: config.child
)
);
}
}
class ExampleDragSource extends StatelessComponent {
ExampleDragSource({
Key key,
this.color,
this.heavy: false,
this.under: true,
this.child
}) : super(key: key);
final Color color;
final bool heavy;
final bool under;
final Widget child;
static const double kDotSize = 50.0;
static const double kHeavyMultiplier = 1.5;
static const double kFingerSize = 50.0;
Widget build(BuildContext context) {
double size = kDotSize;
if (heavy)
size *= kHeavyMultiplier;
Widget contents = new DefaultTextStyle(
style: Theme.of(context).text.body1.copyWith(textAlign: TextAlign.center),
child: new Dot(
color: color,
size: size,
child: new Center(child: child)
)
);
Widget feedback = new Opacity(
opacity: 0.75,
child: contents
);
Offset feedbackOffset;
DragAnchor anchor;
if (!under) {
feedback = new Transform(
transform: new Matrix4.identity()
..translate(-size / 2.0, -(size / 2.0 + kFingerSize)),
child: feedback
);
feedbackOffset = const Offset(0.0, -kFingerSize);
anchor = DragAnchor.pointer;
} else {
feedbackOffset = Offset.zero;
anchor = DragAnchor.child;
}
if (heavy) {
return new LongPressDraggable<Color>(
data: color,
child: contents,
feedback: feedback,
feedbackOffset: feedbackOffset,
dragAnchor: anchor
);
} else {
return new Draggable<Color>(
data: color,
child: contents,
feedback: feedback,
feedbackOffset: feedbackOffset,
dragAnchor: anchor
);
}
}
}
class DashOutlineCirclePainter extends CustomPainter {
const DashOutlineCirclePainter();
static const int segments = 17;
static const double deltaTheta = math.PI * 2 / segments; // radians
static const double segmentArc = deltaTheta / 2.0; // radians
static const double startOffset = 1.0; // radians
void paint(Canvas canvas, Size size) {
final double radius = size.shortestSide / 2.0;
final Paint paint = new Paint()
..color = const Color(0xFF000000)
..style = PaintingStyle.stroke
..strokeWidth = radius / 10.0;
final Path path = new Path();
final Rect box = Point.origin & size;
for (double theta = 0.0; theta < math.PI * 2.0; theta += deltaTheta)
path.addArc(box, theta + startOffset, segmentArc);
canvas.drawPath(path, paint);
}
bool shouldRepaint(DashOutlineCirclePainter oldPainter) => false;
}
class MovableBall extends StatelessComponent {
MovableBall(this.position, this.ballPosition, this.callback);
final int position;
final int ballPosition;
final ValueChanged<int> callback;
static final GlobalKey kBallKey = new GlobalKey();
static const double kBallSize = 50.0;
Widget build(BuildContext context) {
Widget ball = new DefaultTextStyle(
style: Theme.of(context).text.body1.copyWith(
textAlign: TextAlign.center,
color: Colors.white
),
child: new Dot(
key: kBallKey,
color: Colors.blue[700],
size: kBallSize,
tappable: true,
child: new Center(child: new Text('BALL'))
)
);
Widget dashedBall = new Container(
width: kBallSize,
height: kBallSize,
child: new CustomPaint(
painter: const DashOutlineCirclePainter()
)
);
if (position == ballPosition) {
return new Draggable<bool>(
data: true,
child: ball,
childWhenDragging: dashedBall,
feedback: ball,
maxSimultaneousDrags: 1
);
} else {
return new DragTarget<bool>(
onAccept: (bool data) { callback(position); },
builder: (BuildContext context, List<bool> accepted, List<bool> rejected) {
return dashedBall;
}
);
}
}
}
class DragAndDropApp extends StatefulComponent {
DragAndDropAppState createState() => new DragAndDropAppState();
}
class DragAndDropAppState extends State<DragAndDropApp> {
int position = 1;
void moveBall(int newPosition) {
setState(() { position = newPosition; });
}
Widget build(BuildContext context) {
return new Scaffold(
toolBar: new ToolBar(
center: new Text('Drag and Drop Flutter Demo')
),
body: new Column(
children: <Widget>[
new Flexible(
child: new Row(
children: <Widget>[
new ExampleDragSource(
color: Colors.yellow[300],
under: true,
heavy: false,
child: new Text('under')
),
new ExampleDragSource(
color: Colors.green[300],
under: false,
heavy: true,
child: new Text('long-press above')
),
new ExampleDragSource(
color: Colors.indigo[300],
under: false,
heavy: false,
child: new Text('above')
),
],
alignItems: FlexAlignItems.center,
justifyContent: FlexJustifyContent.spaceAround
)
),
new Flexible(
child: new Row(
children: <Widget>[
new Flexible(child: new ExampleDragTarget()),
new Flexible(child: new ExampleDragTarget()),
new Flexible(child: new ExampleDragTarget()),
new Flexible(child: new ExampleDragTarget()),
]
)
),
new Flexible(
child: new Row(
children: <Widget>[
new MovableBall(1, position, moveBall),
new MovableBall(2, position, moveBall),
new MovableBall(3, position, moveBall),
],
justifyContent: FlexJustifyContent.spaceAround
)
),
]
)
);
}
}
void main() {
runApp(new MaterialApp(
title: 'Drag and Drop Flutter Demo',
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new DragAndDropApp()
}
));
}

View File

@@ -1,4 +0,0 @@
name: widgets
uses-material-design: true
assets:
- assets/starcircle.png

View File

@@ -1,138 +0,0 @@
// Copyright (c) 2015, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:ui' as ui show window;
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
void main() {
timeDilation = 8.0;
runApp(
new MaterialApp(
title: "Hero Under",
routes: {
'/': (RouteArguments args) => new HeroDemo()
}
)
);
}
const String kImageSrc = 'http://uploads0.wikiart.org/images/m-c-escher/crab-canon.jpg!Blog.jpg';
const String kText = """
Low-crab diets are dietary programs that restrict crustacean consumption, often for the treatment of obesity or diabetes. Foods high in easily digestible crustaceans (e.g., crab, lobster, shrimp) are limited or replaced with foods made from other animals (e.g., poultry, beef, pork) and other crustaceans that are hard to digest (e.g., barnacles), although krill are often allowed. The amount of crab allowed varies with different low-crab diets.
""";
class HeroImage extends StatelessComponent {
HeroImage({ this.size });
final Size size;
Widget build(BuildContext context) {
return new Hero(
child: new Container(
width: size.width,
height: size.height,
decoration: new BoxDecoration(
backgroundImage: new BackgroundImage(
fit: ImageFit.cover,
image: imageCache.load(kImageSrc)
)
)
),
tag: HeroImage
);
}
}
class HeroDemo extends StatelessComponent {
Widget build(BuildContext context) {
return new Scaffold(
toolBar: new ToolBar(
left: new IconButton(icon: Icons.menu),
center: new Text('Diets')
),
body: new Center(
child: new GestureDetector(
onTap: () => Navigator.push(context, new CrabRoute()),
child: new Card(
child: new Row(
children: <Widget>[
new HeroImage(
size: const Size(100.0, 100.0)
),
new Flexible(
child: new Container(
padding: const EdgeDims.all(10.0),
child: new Text(
"Low Crab Diet",
style: Theme.of(context).text.title
)
)
)
]
)
)
)
)
);
}
}
class CrabRoute extends MaterialPageRoute {
CrabRoute() : super(builder: (BuildContext context) => new CrabPage());
void insertHeroOverlayEntry(OverlayEntry entry, Object tag, OverlayState overlay) {
overlay.insert(entry, above: overlayEntries.first);
}
}
class CrabPage extends StatelessComponent {
Widget build(BuildContext context) {
TextStyle titleStyle = Typography.white.display2.copyWith(color: Colors.white);
return new Material(
color: const Color(0x00000000),
child: new Block(
children: <Widget>[
new Stack(
children: <Widget>[
new HeroImage(
size: new Size(ui.window.size.width, ui.window.size.width)
),
new ToolBar(
padding: new EdgeDims.only(top: ui.window.padding.top),
backgroundColor: const Color(0x00000000),
left: new IconButton(
icon: Icons.arrow_back,
onPressed: () => Navigator.pop(context)
),
right: <Widget>[
new IconButton(icon: Icons.more_vert)
]
),
new Positioned(
bottom: 10.0,
left: 10.0,
child: new Text("Low Crab Diet", style: titleStyle)
)
]
),
new Material(
child: new Container(
padding: const EdgeDims.all(10.0),
child: new Column(
children: <Widget>[
new Text(kText, style: Theme.of(context).text.body1),
new Container(height: 800.0),
],
alignItems: FlexAlignItems.start
)
)
)
]
)
);
}
}

View File

@@ -1,73 +0,0 @@
// Copyright 2015, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:flutter/http.dart' as http;
import 'package:flutter/material.dart';
void main() {
runApp(
new MaterialApp(
title: "HTTP POST Example",
routes: {
'/': (RouteArguments args) => const PostDemo()
}
)
);
}
class PostDemo extends StatefulComponent {
const PostDemo();
PostDemoState createState() => new PostDemoState();
}
class PostDemoState extends State<PostDemo> {
String _response = null;
void initState() {
_refresh();
super.initState();
}
Future _refresh() async {
setState(() {
_response = null;
});
http.Response response = await http.post(
"http://httpbin.org/post",
body: '{"foo": "bar"}',
headers: { "Content-Type": "application/json", "baz": "qux" }
);
setState(() {
_response = response.body;
});
}
Widget build(BuildContext context) {
return new Scaffold(
toolBar: new ToolBar(
center: new Text("HTTP POST example")
),
body: new Material(
child: new Block(
children: <Widget>[
new Text(
"${_response ?? 'Loading...'}",
style: Typography.black.body1
)
]
)
),
floatingActionButton: new FloatingActionButton(
tooltip: 'Refresh',
child: new Icon(
icon: Icons.refresh
),
onPressed: _refresh
)
);
}
}

View File

@@ -1,67 +0,0 @@
// Copyright 2015 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/material.dart';
import 'package:flutter/rendering.dart';
class IndexedStackDemo extends StatefulComponent {
IndexedStackDemoState createState() => new IndexedStackDemoState();
}
class IndexedStackDemoState extends State<IndexedStackDemo> {
int _itemCount = 7;
int _itemIndex = 0;
void _handleTap() {
setState(() {
_itemIndex = (_itemIndex + 1) % _itemCount;
});
}
List<PopupMenuItem<int>> _buildMenu() {
TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold);
String pad = '';
return new List<PopupMenuItem>.generate(_itemCount, (int i) {
pad += '-';
return new PopupMenuItem<int>(value: i, child: new Text('$pad Hello World $i $pad', style: style));
});
}
Widget build(BuildContext context) {
List<PopupMenuItem<int>> items = _buildMenu();
IndexedStack indexedStack = new IndexedStack(
children: items,
index: _itemIndex,
alignment: const FractionalOffset(0.5, 0.0)
);
return new Scaffold(
toolBar: new ToolBar(center: new Text('IndexedStackDemo Demo')),
body: new GestureDetector(
onTap: _handleTap,
child: new Center(
child: new Container(
child: indexedStack,
padding: const EdgeDims.all(8.0),
decoration: new BoxDecoration(border: new Border.all(color: Theme.of(context).accentColor))
)
)
)
);
}
}
void main() {
runApp(new MaterialApp(
title: 'IndexedStackDemo',
theme: new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200]
),
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new IndexedStackDemo(),
}
));
}

View File

@@ -1,102 +0,0 @@
// Copyright 2015 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/material.dart';
const double _kHeight = 150.0;
const Duration _kEffectDuration = const Duration(seconds: 1);
class MimicDemo extends StatefulComponent {
_MimicDemoState createState() => new _MimicDemoState();
}
class _MimicDemoState extends State<MimicDemo> {
GlobalKey<MimicableState> _orange = new GlobalKey<MimicableState>();
GlobalKey _targetContainer = new GlobalKey();
bool _slotForOrangeOnTop = false;
bool _orangeOnTop = false;
void _handleTap() {
if (_slotForOrangeOnTop)
return;
setState(() {
_slotForOrangeOnTop = true;
});
MimicOverlayEntry entry = _orange.currentState.liftToOverlay();
entry.animateTo(targetKey: _targetContainer, duration: _kEffectDuration, curve: Curves.ease).then((_) {
setState(() {
_orangeOnTop = true;
});
entry.dispose();
});
}
void _reset() {
setState(() {
_slotForOrangeOnTop = false;
_orangeOnTop = false;
});
}
Widget _buildOrange() {
return new Mimicable(
key: _orange,
child: new Container(
height: _kHeight,
decoration: new BoxDecoration(
backgroundColor: Colors.deepOrange[500]
)
)
);
}
Widget build(BuildContext context) {
List<Widget> children = <Widget>[
new Container(
height: _kHeight,
decoration: new BoxDecoration(
backgroundColor: Colors.amber[500]
)
),
new AnimatedContainer(
key: _targetContainer,
height: _slotForOrangeOnTop ? _kHeight : 0.0,
duration: _kEffectDuration,
curve: Curves.ease,
child: _orangeOnTop ? _buildOrange() : null
),
new Container(
height: _kHeight,
decoration: new BoxDecoration(
backgroundColor: Colors.green[500]
)
),
new Container(
height: _kHeight,
decoration: new BoxDecoration(
backgroundColor: Colors.blue[500]
)
),
];
if (!_orangeOnTop)
children.add(_buildOrange());
return new GestureDetector(
onTap: _handleTap,
onLongPress: _reset,
child: new Block(children: children)
);
}
}
void main() {
runApp(new MaterialApp(
title: 'Mimic Demo',
routes: {
'/': (_) => new MimicDemo()
}
));
}

View File

@@ -1,243 +0,0 @@
// Copyright 2015 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 'dart:math' as math;
import 'package:flutter/material.dart';
class LauncherData {
const LauncherData({ this.url, this.title });
final String url;
final String title;
}
const List<LauncherData> _kLauncherData = const <LauncherData>[
const LauncherData(
url: 'mojo:noodles_view',
title: 'Noodles'
),
const LauncherData(
url: 'mojo:shapes_view',
title: 'Shapes'
),
];
const Size _kInitialWindowSize = const Size(200.0, 200.0);
const double _kWindowPadding = 10.0;
enum WindowSide {
topCenter,
topRight,
bottomRight,
}
class WindowDecoration extends StatelessComponent {
WindowDecoration({
Key key,
this.side,
this.color,
this.onTap,
this.onPanUpdate
}) : super(key: key);
final WindowSide side;
final Color color;
final GestureTapCallback onTap;
final GesturePanUpdateCallback onPanUpdate;
Widget build(BuildContext context) {
double top, right, bottom, left, width, height;
height = _kWindowPadding * 2.0;
if (side == WindowSide.topCenter || side == WindowSide.topRight)
top = 0.0;
if (side == WindowSide.topRight || side == WindowSide.bottomRight) {
right = 0.0;
width = _kWindowPadding * 2.0;
}
if (side == WindowSide.topCenter) {
left = _kWindowPadding;
right = _kWindowPadding;
}
if (side == WindowSide.bottomRight)
bottom = 0.0;
return new Positioned(
top: top,
right: right,
bottom: bottom,
left: left,
width: width,
height: height,
child: new GestureDetector(
onTap: onTap,
onPanUpdate: onPanUpdate,
child: new Container(
decoration: new BoxDecoration(
backgroundColor: color
)
)
)
);
}
}
class Window extends StatefulComponent {
Window({ Key key, this.child, this.onClose }) : super(key: key);
final ChildViewConnection child;
final ValueChanged<ChildViewConnection> onClose;
_WindowState createState() => new _WindowState();
}
class _WindowState extends State<Window> {
Offset _offset = Offset.zero;
Size _size = _kInitialWindowSize;
void _handleResizerDrag(Offset delta) {
setState(() {
_size = new Size(
math.max(0.0, _size.width + delta.dx),
math.max(0.0, _size.height + delta.dy)
);
});
}
void _handleRepositionDrag(Offset delta) {
setState(() {
_offset += delta;
});
}
void _handleClose() {
config.onClose(config.child);
}
Widget build(BuildContext context) {
return new Positioned(
left: _offset.dx,
top: _offset.dy,
width: _size.width + _kWindowPadding * 2.0,
height: _size.height + _kWindowPadding * 2.0,
child: new Stack(
children: <Widget>[
new WindowDecoration(
side: WindowSide.topCenter,
onPanUpdate: _handleRepositionDrag,
color: Colors.green[200]
),
new WindowDecoration(
side: WindowSide.topRight,
onTap: _handleClose,
color: Colors.red[200]
),
new WindowDecoration(
side: WindowSide.bottomRight,
onPanUpdate: _handleResizerDrag,
color: Colors.blue[200]
),
new Container(
padding: const EdgeDims.all(_kWindowPadding),
child: new Material(
elevation: 8,
child: new ChildView(child: config.child)
)
)
]
)
);
}
}
class LauncherItem extends StatelessComponent {
LauncherItem({
Key key,
this.url,
this.child,
this.onLaunch
}) : super(key: key);
final String url;
final Widget child;
final ValueChanged<ChildViewConnection> onLaunch;
Widget build(BuildContext context) {
return new RaisedButton(
onPressed: () { onLaunch(new ChildViewConnection(url: url)); },
child: child
);
}
}
class Launcher extends StatelessComponent {
Launcher({ Key key, this.items }) : super(key: key);
final List<Widget> items;
Widget build(BuildContext context) {
return new Row(
justifyContent: FlexJustifyContent.center,
children: items
);
}
}
class WindowManager extends StatefulComponent {
_WindowManagerState createState() => new _WindowManagerState();
}
class _WindowManagerState extends State<WindowManager> {
List<ChildViewConnection> _windows = <ChildViewConnection>[];
void _handleLaunch(ChildViewConnection child) {
setState(() {
_windows.add(child);
});
}
void _handleClose(ChildViewConnection child) {
setState(() {
_windows.remove(child);
});
}
Widget build(BuildContext context) {
return new Material(
child: new Stack(
children: <Widget>[
new Positioned(
left: 0.0,
right: 0.0,
bottom: 0.0,
child: new Launcher(items: _kLauncherData.map((LauncherData data) {
return new LauncherItem(
url: data.url,
onLaunch: _handleLaunch,
child: new Text(data.title)
);
}).toList())
)
]..addAll(_windows.map((ChildViewConnection child) {
return new Window(
key: new ObjectKey(child),
onClose: _handleClose,
child: child
);
}))
)
);
}
}
void main() {
runApp(new MaterialApp(
title: 'Mozart',
routes: <String, RouteBuilder>{ '/': (_) => new WindowManager() }
));
}

View File

@@ -1,186 +0,0 @@
// Copyright 2015 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/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class CardModel {
CardModel(this.value, this.height, this.color);
int value;
double height;
Color color;
String get label => "Card $value";
Key get key => new ObjectKey(this);
GlobalKey get targetKey => new GlobalObjectKey(this);
}
enum MarkerType { topLeft, bottomRight, touch }
class _MarkerPainter extends CustomPainter {
const _MarkerPainter({
this.size,
this.type
});
final double size;
final MarkerType type;
void paint(Canvas canvas, _) {
Paint paint = new Paint()..color = const Color(0x8000FF00);
double r = size / 2.0;
canvas.drawCircle(new Point(r, r), r, paint);
paint
..color = const Color(0xFFFFFFFF)
..style = PaintingStyle.stroke
..strokeWidth = 1.0;
if (type == MarkerType.topLeft) {
canvas.drawLine(new Point(r, r), new Point(r + r - 1.0, r), paint);
canvas.drawLine(new Point(r, r), new Point(r, r + r - 1.0), paint);
}
if (type == MarkerType.bottomRight) {
canvas.drawLine(new Point(r, r), new Point(1.0, r), paint);
canvas.drawLine(new Point(r, r), new Point(r, 1.0), paint);
}
}
bool shouldRepaint(_MarkerPainter oldPainter) {
return oldPainter.size != size
|| oldPainter.type != type;
}
}
class Marker extends StatelessComponent {
Marker({
this.type: MarkerType.touch,
this.position,
this.size: 40.0,
Key key
}) : super(key: key);
final Point position;
final double size;
final MarkerType type;
Widget build(BuildContext context) {
return new Positioned(
left: position.x - size / 2.0,
top: position.y - size / 2.0,
width: size,
height: size,
child: new IgnorePointer(
child: new CustomPaint(
painter: new _MarkerPainter(
size: size,
type: type
)
)
)
);
}
}
class OverlayGeometryApp extends StatefulComponent {
OverlayGeometryAppState createState() => new OverlayGeometryAppState();
}
class OverlayGeometryAppState extends State<OverlayGeometryApp> {
static const TextStyle cardLabelStyle =
const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold);
List<CardModel> cardModels;
Map<MarkerType, Point> markers = new Map<MarkerType, Point>();
double markersScrollOffset;
ScrollListener scrollListener;
void initState() {
super.initState();
List<double> cardHeights = <double>[
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0
];
cardModels = new List<CardModel>.generate(cardHeights.length, (int i) {
Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardHeights.length);
return new CardModel(i, cardHeights[i], color);
});
}
void handleScroll(double offset) {
setState(() {
double dy = markersScrollOffset - offset;
markersScrollOffset = offset;
for (MarkerType type in markers.keys) {
Point oldPosition = markers[type];
markers[type] = new Point(oldPosition.x, oldPosition.y + dy);
}
});
}
void handlePointerDown(GlobalKey target, PointerDownEvent event) {
setState(() {
markers[MarkerType.touch] = event.position;
final RenderBox box = target.currentContext.findRenderObject();
markers[MarkerType.topLeft] = box.localToGlobal(new Point(0.0, 0.0));
final Size size = box.size;
markers[MarkerType.bottomRight] = box.localToGlobal(new Point(size.width, size.height));
final ScrollableState scrollable = Scrollable.of(target.currentContext);
markersScrollOffset = scrollable.scrollOffset;
});
}
Widget builder(BuildContext context, int index) {
if (index >= cardModels.length)
return null;
CardModel cardModel = cardModels[index];
return new Listener(
key: cardModel.key,
onPointerDown: (PointerDownEvent event) { return handlePointerDown(cardModel.targetKey, event); },
child: new Card(
key: cardModel.targetKey,
color: cardModel.color,
child: new Container(
height: cardModel.height,
padding: const EdgeDims.all(8.0),
child: new Center(child: new Text(cardModel.label, style: cardLabelStyle))
)
)
);
}
Widget build(BuildContext context) {
List<Widget> layers = <Widget>[
new Scaffold(
toolBar: new ToolBar(center: new Text('Tap a Card')),
body: new Container(
padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0),
child: new ScrollableMixedWidgetList(
builder: builder,
token: cardModels.length,
onScroll: handleScroll
)
)
)
];
for (MarkerType type in markers.keys)
layers.add(new Marker(type: type, position: markers[type]));
return new Stack(children: layers);
}
}
void main() {
runApp(new MaterialApp(
theme: new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200]
),
title: 'Cards',
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new OverlayGeometryApp()
}
));
}

View File

@@ -1,149 +0,0 @@
// Copyright 2015 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/material.dart';
class CardModel {
CardModel(this.value, this.size, this.color);
int value;
Size size;
Color color;
String get label => "Card $value";
Key get key => new ObjectKey(this);
}
class PageableListApp extends StatefulComponent {
PageableListAppState createState() => new PageableListAppState();
}
class PageableListAppState extends State<PageableListApp> {
void initState() {
super.initState();
List<Size> cardSizes = [
[100.0, 300.0], [300.0, 100.0], [200.0, 400.0], [400.0, 400.0], [300.0, 400.0]
]
.map((args) => new Size(args[0], args[1]))
.toList();
cardModels = new List<CardModel>.generate(cardSizes.length, (int i) {
Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardSizes.length);
return new CardModel(i, cardSizes[i], color);
});
}
static const TextStyle cardLabelStyle =
const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold);
List<CardModel> cardModels;
Size pageSize = new Size(200.0, 200.0);
Axis scrollDirection = Axis.horizontal;
bool itemsWrap = false;
Widget buildCard(CardModel cardModel) {
Widget card = new Card(
color: cardModel.color,
child: new Container(
width: cardModel.size.width,
height: cardModel.size.height,
padding: const EdgeDims.all(8.0),
child: new Center(child: new Text(cardModel.label, style: cardLabelStyle))
)
);
BoxConstraints constraints = (scrollDirection == Axis.vertical)
? new BoxConstraints.tightFor(height: pageSize.height)
: new BoxConstraints.tightFor(width: pageSize.width);
return new Container(
key: cardModel.key,
constraints: constraints,
child: new Center(child: card)
);
}
void switchScrollDirection() {
setState(() {
scrollDirection = (scrollDirection == Axis.vertical)
? Axis.horizontal
: Axis.vertical;
});
}
void toggleItemsWrap() {
setState(() {
itemsWrap = !itemsWrap;
});
}
Widget _buildDrawer() {
return new Drawer(
child: new Block(children: <Widget>[
new DrawerHeader(child: new Text('Options')),
new DrawerItem(
icon: Icons.more_horiz,
selected: scrollDirection == Axis.horizontal,
child: new Text('Horizontal Layout'),
onPressed: switchScrollDirection
),
new DrawerItem(
icon: Icons.more_vert,
selected: scrollDirection == Axis.vertical,
child: new Text('Vertical Layout'),
onPressed: switchScrollDirection
),
new DrawerItem(
onPressed: toggleItemsWrap,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Scrolling wraps around')),
new Checkbox(value: itemsWrap)
]
)
)
])
);
}
Widget _buildToolBar() {
return new ToolBar(
center: new Text('PageableList'),
right: <Widget>[
new Text(scrollDirection == Axis.horizontal ? "horizontal" : "vertical")
]
);
}
Widget _buildBody(BuildContext context) {
return new PageableList(
children: cardModels.map(buildCard),
itemsWrap: itemsWrap,
scrollDirection: scrollDirection
);
}
Widget build(BuildContext context) {
return new IconTheme(
data: const IconThemeData(color: Colors.white),
child: new Scaffold(
toolBar: _buildToolBar(),
drawer: _buildDrawer(),
body: _buildBody(context)
)
);
}
}
void main() {
runApp(new MaterialApp(
title: 'PageableList',
theme: new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200]
),
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new PageableListApp(),
}
));
}

View File

@@ -1,4 +0,0 @@
name: sky_widgets_examples
dependencies:
flutter:
path: ../../packages/flutter

View File

@@ -1,79 +0,0 @@
// Copyright 2016 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/material.dart';
import 'package:sky_services/sky/input_event.mojom.dart' as mojom;
GlobalKey _key = new GlobalKey();
void main() {
runApp(
new MaterialApp(
title: "Hardware Key Demo",
routes: <String, RouteBuilder>{
'/': (RouteArguments args) {
return new Scaffold(
toolBar: new ToolBar(
center: new Text("Hardware Key Demo")
),
body: new Material(
child: new RawKeyboardDemo(
key: _key
)
)
);
}
}
)
);
}
class RawKeyboardDemo extends StatefulComponent {
RawKeyboardDemo({ GlobalKey key }) : super(key: key);
_HardwareKeyDemoState createState() => new _HardwareKeyDemoState();
}
class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
mojom.InputEvent _event = null;
void _handleKey(mojom.InputEvent event) {
setState(() {
_event = event;
});
}
Widget build(BuildContext context) {
bool focused = Focus.at(context);
Widget child;
if (!focused) {
child = new GestureDetector(
onTap: () {
Focus.moveTo(config.key);
},
child: new Center(
child: new Text('Tap to focus', style: Typography.black.display1)
)
);
} else if (_event == null) {
child = new Center(
child: new Text('Press a key', style: Typography.black.display1)
);
} else {
child = new Column(
children: <Widget>[
new Text('${_event.type}', style: Typography.black.body2),
new Text('${_event.keyData.keyCode}', style: Typography.black.display4)
],
justifyContent: FlexJustifyContent.center
);
}
return new RawKeyboardListener(
focused: focused,
onKey: _handleKey,
child: child
);
}
}

View File

@@ -1,87 +0,0 @@
// Copyright (c) 2016, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:ui' as ui show window;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
class ExampleApp extends StatefulComponent {
ExampleState createState() => new ExampleState();
}
const List<double> _ratios = const <double>[ 1.0, 1.8, 1.3, 2.4, 2.5, 2.6, 3.9 ];
class ExampleState extends State<ExampleApp> {
int _index = 0;
double _ratio = _ratios[0];
final EdgeDims padding = new EdgeDims.TRBL(
ui.window.padding.top,
ui.window.padding.right,
ui.window.padding.bottom,
ui.window.padding.left
);
void _handlePressed() {
setState(() {
_index++;
_index = _index % _ratios.length;
_ratio = _ratios[_index];
});
}
Widget build(BuildContext context) {
const double size = 200.0; // 200 logical pixels
TextStyle style = new TextStyle(color: const Color(0xFF0000000));
return new MediaQuery(
data: new MediaQueryData(
size: ui.window.size,
devicePixelRatio: _ratio,
padding: padding
),
child: new AssetVendor(
bundle: rootBundle,
devicePixelRatio: _ratio,
child: new Material(
child: new Padding(
padding: const EdgeDims.symmetric(vertical: 48.0),
child: new Column(
children: <Widget>[
new AssetImage(
name: 'assets/2.0x/starcircle.png',
height: size,
width: size,
fit: ImageFit.fill
),
new Text('Image designed for pixel ratio 2.0', style: style),
new AssetImage(
name: 'assets/starcircle.png',
height: size,
width: size,
fit: ImageFit.fill
),
new Text(
'Image variant for pixel ratio: ' + _ratio.toString(),
style: style
),
new RaisedButton(
child: new Text('Change pixel ratio', style: style),
onPressed: _handlePressed
)
],
justifyContent: FlexJustifyContent.spaceBetween
)
)
)
)
);
}
}
main() {
runApp(new ExampleApp());
}

View File

@@ -1,76 +0,0 @@
// Copyright 2015 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:intl/intl.dart';
import 'package:flutter/material.dart';
final NumberFormat _dd = new NumberFormat("00", "en_US");
class _Item extends StatelessComponent {
_Item(this.index);
int index;
Widget build(BuildContext context) {
return new Text('Item ${_dd.format(index)}',
key: new ValueKey<int>(index),
style: Theme.of(context).text.title
);
}
}
class ScrollbarApp extends StatefulComponent {
ScrollbarAppState createState() => new ScrollbarAppState();
}
class ScrollbarAppState extends State<ScrollbarApp> {
final int _itemCount = 20;
final double _itemExtent = 50.0;
final ScrollbarPainter _scrollbarPainter = new ScrollbarPainter();
Widget _buildMenu(BuildContext context) {
return new ScrollableList(
itemExtent: _itemExtent,
scrollableListPainter: _scrollbarPainter,
children: new List<Widget>.generate(_itemCount, (int i) => new _Item(i))
);
}
Widget build(BuildContext context) {
Widget scrollable = new Container(
margin: new EdgeDims.symmetric(horizontal: 6.0), // TODO(hansmuller) 6.0 should be based on _kScrollbarThumbWidth
child: new Center(
widthFactor: 1.0,
heightFactor: 1.0,
child: new Container(
width: 80.0,
height: _itemExtent * 5.0,
child: _buildMenu(context)
)
)
);
return new Scaffold(
toolBar: new ToolBar(center: new Text('Scrollbar Demo')),
body: new Container(
padding: new EdgeDims.all(12.0),
child: new Center(child: new Card(child: scrollable))
)
);
}
}
void main() {
runApp(new MaterialApp(
title: 'ScrollbarApp',
theme: new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200]
),
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new ScrollbarApp(),
}
));
}