A Flutter logo widget. (#5382)

Instead of a PNG, the Flutter gallery widget is now drawn in code.

There's now a FlutterLogoDecoration class that paints the flutter logo
anywhere you can use a Decoration (e.g. AnimatedContainer).

There's now a FlutterLogo class that honors the IconTheme.

The About dialog box API now takes a Widget for the applicationIcon,
instead of an ImageProvider. It uses IconTheme to make the icon the
right size instead of using an Image widget.

Add padding, duration, and curve properties to the DrawerHeader.
Make the child of a DrawerHeader optional.

Clean up UserAccuntsDrawerHeader a bit.

Add some useful properties and methods to EdgeInsets.

Add some debug logic to RenderDecoratedBox to catch unpaired
save/restore calls when possible.

Make GestureDetector fill its parent if it has no children. Fixes
https://github.com/flutter/flutter/issues/5380
This commit is contained in:
Ian Hickson
2016-08-15 12:50:24 -07:00
committed by GitHub
parent e2d0917ed6
commit 955b3e21f7
14 changed files with 788 additions and 65 deletions

View File

@@ -2,6 +2,8 @@
// 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/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -16,6 +18,69 @@ class LinkTextSpan extends TextSpan {
);
}
class GalleryDrawerHeader extends StatefulWidget {
const GalleryDrawerHeader({ Key key }) : super(key: key);
@override
_GalleryDrawerHeaderState createState() => new _GalleryDrawerHeaderState();
}
class _GalleryDrawerHeaderState extends State<GalleryDrawerHeader> {
bool _logoHasName = true;
bool _logoHorizontal = true;
Map<int, Color> _swatch = Colors.blue;
@override
Widget build(BuildContext context) {
final double systemTopPadding = MediaQuery.of(context).padding.top;
return new DrawerHeader(
decoration: new FlutterLogoDecoration(
margin: new EdgeInsets.fromLTRB(12.0, 12.0 + systemTopPadding, 12.0, 12.0),
style: _logoHasName ? _logoHorizontal ? FlutterLogoStyle.horizontal
: FlutterLogoStyle.stacked
: FlutterLogoStyle.markOnly,
swatch: _swatch,
),
duration: const Duration(milliseconds: 750),
child: new GestureDetector(
onLongPress: () {
setState(() {
_logoHorizontal = !_logoHorizontal;
if (!_logoHasName)
_logoHasName = true;
});
},
onTap: () {
setState(() {
_logoHasName = !_logoHasName;
});
},
onDoubleTap: () {
setState(() {
final List<Map<int, Color>> options = <Map<int, Color>>[];
if (_swatch != Colors.blue)
options.addAll(<Map<int, Color>>[Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue]);
if (_swatch != Colors.amber)
options.addAll(<Map<int, Color>>[Colors.amber, Colors.amber, Colors.amber]);
if (_swatch != Colors.red)
options.addAll(<Map<int, Color>>[Colors.red, Colors.red, Colors.red]);
if (_swatch != Colors.indigo)
options.addAll(<Map<int, Color>>[Colors.indigo, Colors.indigo, Colors.indigo]);
if (_swatch != Colors.pink)
options.addAll(<Map<int, Color>>[Colors.pink]);
if (_swatch != Colors.purple)
options.addAll(<Map<int, Color>>[Colors.purple]);
if (_swatch != Colors.cyan)
options.addAll(<Map<int, Color>>[Colors.cyan]);
_swatch = options[new math.Random().nextInt(options.length)];
});
}
)
);
}
}
class GalleryDrawer extends StatelessWidget {
GalleryDrawer({
Key key,
@@ -41,24 +106,14 @@ class GalleryDrawer extends StatelessWidget {
@override
Widget build(BuildContext context) {
ThemeData themeData = Theme.of(context);
TextStyle aboutTextStyle = themeData.textTheme.body2;
TextStyle aboutLinkStyle = themeData.textTheme.body2.copyWith(color: themeData.accentColor);
final ThemeData themeData = Theme.of(context);
final TextStyle aboutTextStyle = themeData.textTheme.body2;
final TextStyle aboutLinkStyle = themeData.textTheme.body2.copyWith(color: themeData.accentColor);
return new Drawer(
child: new Block(
children: <Widget>[
new DrawerHeader(
child: new Center(
child: new Padding(
padding: const EdgeInsets.all(16.0),
child: new Image.asset(
'packages/flutter_gallery_assets/drawer_logo.png',
fit: ImageFit.contain
)
)
)
),
new GalleryDrawerHeader(),
new DrawerItem(
icon: new Icon(Icons.brightness_5),
onPressed: () { onThemeChanged(true); },
@@ -119,8 +174,9 @@ class GalleryDrawer extends StatelessWidget {
)
),
new AboutDrawerItem(
icon: new FlutterLogo(),
applicationVersion: '2016 Q3 Preview',
applicationIcon: new AssetImage('packages/flutter_gallery_assets/about_logo.png'),
applicationIcon: new FlutterLogo(),
applicationLegalese: '© 2016 The Chromium Authors',
aboutBoxChildren: <Widget>[
new Padding(