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:
9
dev/manual_tests/.gitignore
vendored
Normal file
9
dev/manual_tests/.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
.atom
|
||||
.DS_Store
|
||||
.buildlog
|
||||
.idea
|
||||
.packages
|
||||
.pub/
|
||||
build/
|
||||
packages
|
||||
pubspec.lock
|
||||
469
dev/manual_tests/card_collection.dart
Normal file
469
dev/manual_tests/card_collection.dart
Normal file
@@ -0,0 +1,469 @@
|
||||
// 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(),
|
||||
}
|
||||
));
|
||||
}
|
||||
290
dev/manual_tests/drag_and_drop.dart
Normal file
290
dev/manual_tests/drag_and_drop.dart
Normal file
@@ -0,0 +1,290 @@
|
||||
// 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()
|
||||
}
|
||||
));
|
||||
}
|
||||
243
dev/manual_tests/mozart.dart
Normal file
243
dev/manual_tests/mozart.dart
Normal file
@@ -0,0 +1,243 @@
|
||||
// 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() }
|
||||
));
|
||||
}
|
||||
186
dev/manual_tests/overlay_geometry.dart
Normal file
186
dev/manual_tests/overlay_geometry.dart
Normal file
@@ -0,0 +1,186 @@
|
||||
// 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()
|
||||
}
|
||||
));
|
||||
}
|
||||
149
dev/manual_tests/pageable_list.dart
Normal file
149
dev/manual_tests/pageable_list.dart
Normal file
@@ -0,0 +1,149 @@
|
||||
// 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(),
|
||||
}
|
||||
));
|
||||
}
|
||||
4
dev/manual_tests/pubspec.yaml
Normal file
4
dev/manual_tests/pubspec.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
name: flutter_manual_tests
|
||||
dependencies:
|
||||
flutter:
|
||||
path: ../../packages/flutter
|
||||
79
dev/manual_tests/raw_keyboard.dart
Normal file
79
dev/manual_tests/raw_keyboard.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
// 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
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user