Commit e4b1eab8 authored by Adam Barth's avatar Adam Barth

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.
parent efa36de7
.atom
.DS_Store
.buildlog
.idea
.packages
.pub/
build/
packages
pubspec.lock
name: sky_widgets_examples
name: flutter_manual_tests
dependencies:
flutter:
path: ../../packages/flutter
......@@ -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:
```
......
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.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
name: widgets
uses-material-design: true
assets:
- assets/starcircle.png
// 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
)
)
)
]
)
);
}
}
// 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
)
);
}
}
// 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(),
}
));
}
// 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()
}
));
}
// 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());
}
// 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(),
}
));
}
......@@ -45,6 +45,7 @@ class UpdatePackagesCommand extends FlutterCommand {
bool upgrade = argResults['upgrade'];
count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/packages"), upgrade: upgrade);
count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/examples"), upgrade: upgrade);
count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/dev"), upgrade: upgrade);
printStatus('Ran "pub" $count time${count == 1 ? "" : "s"} in ${timer.elapsedMilliseconds} ms');
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment