Adding a default title for Title widget (#12015)
Adds a default title to the Title widget, fixes #6802.
This commit is contained in:
parent
ecb56927de
commit
3e21c07087
@ -84,7 +84,7 @@ class MaterialApp extends StatefulWidget {
|
|||||||
/// The boolean arguments, [routes], and [navigatorObservers], must not be null.
|
/// The boolean arguments, [routes], and [navigatorObservers], must not be null.
|
||||||
MaterialApp({ // can't be const because the asserts use methods on Map :-(
|
MaterialApp({ // can't be const because the asserts use methods on Map :-(
|
||||||
Key key,
|
Key key,
|
||||||
this.title,
|
this.title: '',
|
||||||
this.color,
|
this.color,
|
||||||
this.theme,
|
this.theme,
|
||||||
this.home,
|
this.home,
|
||||||
@ -103,7 +103,8 @@ class MaterialApp extends StatefulWidget {
|
|||||||
this.checkerboardOffscreenLayers: false,
|
this.checkerboardOffscreenLayers: false,
|
||||||
this.showSemanticsDebugger: false,
|
this.showSemanticsDebugger: false,
|
||||||
this.debugShowCheckedModeBanner: true
|
this.debugShowCheckedModeBanner: true
|
||||||
}) : assert(routes != null),
|
}) : assert(title != null),
|
||||||
|
assert(routes != null),
|
||||||
assert(navigatorObservers != null),
|
assert(navigatorObservers != null),
|
||||||
assert(debugShowMaterialGrid != null),
|
assert(debugShowMaterialGrid != null),
|
||||||
assert(showPerformanceOverlay != null),
|
assert(showPerformanceOverlay != null),
|
||||||
|
@ -70,7 +70,7 @@ class WidgetsApp extends StatefulWidget {
|
|||||||
Key key,
|
Key key,
|
||||||
@required this.onGenerateRoute,
|
@required this.onGenerateRoute,
|
||||||
this.onUnknownRoute,
|
this.onUnknownRoute,
|
||||||
this.title,
|
this.title: '',
|
||||||
this.textStyle,
|
this.textStyle,
|
||||||
@required this.color,
|
@required this.color,
|
||||||
this.navigatorObservers: const <NavigatorObserver>[],
|
this.navigatorObservers: const <NavigatorObserver>[],
|
||||||
@ -86,7 +86,8 @@ class WidgetsApp extends StatefulWidget {
|
|||||||
this.debugShowWidgetInspector: false,
|
this.debugShowWidgetInspector: false,
|
||||||
this.debugShowCheckedModeBanner: true,
|
this.debugShowCheckedModeBanner: true,
|
||||||
this.inspectorSelectButtonBuilder,
|
this.inspectorSelectButtonBuilder,
|
||||||
}) : assert(onGenerateRoute != null),
|
}) : assert(title != null),
|
||||||
|
assert(onGenerateRoute != null),
|
||||||
assert(color != null),
|
assert(color != null),
|
||||||
assert(navigatorObservers != null),
|
assert(navigatorObservers != null),
|
||||||
assert(supportedLocales != null && supportedLocales.isNotEmpty),
|
assert(supportedLocales != null && supportedLocales.isNotEmpty),
|
||||||
|
@ -11,18 +11,26 @@ import 'framework.dart';
|
|||||||
/// A widget that describes this app in the operating system.
|
/// A widget that describes this app in the operating system.
|
||||||
class Title extends StatelessWidget {
|
class Title extends StatelessWidget {
|
||||||
/// Creates a widget that describes this app to the operating system.
|
/// Creates a widget that describes this app to the operating system.
|
||||||
|
///
|
||||||
|
/// [title] will default to the empty string if not supplied.
|
||||||
|
/// [color] must be an opaque color (i.e. color.alpha must be 255 (0xFF)).
|
||||||
|
/// [color] and [child] are required arguments.
|
||||||
Title({
|
Title({
|
||||||
Key key,
|
Key key,
|
||||||
this.title,
|
this.title: '',
|
||||||
this.color,
|
@required this.color,
|
||||||
@required this.child,
|
@required this.child,
|
||||||
}) : assert(color == null || color.alpha == 0xFF),
|
}) : assert(title != null),
|
||||||
|
assert(color != null && color.alpha == 0xFF),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
/// A one-line description of this app for use in the window manager.
|
/// A one-line description of this app for use in the window manager.
|
||||||
|
/// Must not be null.
|
||||||
final String title;
|
final String title;
|
||||||
|
|
||||||
/// A color that the window manager should use to identify this app.
|
/// A color that the window manager should use to identify this app. Must be
|
||||||
|
/// an opaque color (i.e. color.alpha must be 255 (0xFF)), and must not be
|
||||||
|
/// null.
|
||||||
final Color color;
|
final Color color;
|
||||||
|
|
||||||
/// The widget below this widget in the tree.
|
/// The widget below this widget in the tree.
|
||||||
@ -42,7 +50,7 @@ class Title extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
void debugFillProperties(DiagnosticPropertiesBuilder description) {
|
void debugFillProperties(DiagnosticPropertiesBuilder description) {
|
||||||
super.debugFillProperties(description);
|
super.debugFillProperties(description);
|
||||||
description.add(new StringProperty('title', title, defaultValue: null));
|
description.add(new StringProperty('title', title, defaultValue: ''));
|
||||||
description.add(new DiagnosticsProperty<Color>('color', color, defaultValue: null));
|
description.add(new DiagnosticsProperty<Color>('color', color, defaultValue: null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('toString control test', (WidgetTester tester) async {
|
testWidgets('toString control test', (WidgetTester tester) async {
|
||||||
@ -14,4 +15,52 @@ void main() {
|
|||||||
);
|
);
|
||||||
expect(widget.toString, isNot(throwsException));
|
expect(widget.toString, isNot(throwsException));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('should handle having no title', (WidgetTester tester) async {
|
||||||
|
final Title widget = new Title(
|
||||||
|
child: new Container(),
|
||||||
|
color: const Color(0xFF00FF00),
|
||||||
|
);
|
||||||
|
expect(widget.toString, isNot(throwsException));
|
||||||
|
expect(widget.title, equals(''));
|
||||||
|
expect(widget.color, equals(const Color(0xFF00FF00)));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should not allow null title or color', (WidgetTester tester) async {
|
||||||
|
expect(() => new Title(
|
||||||
|
title: null,
|
||||||
|
color: const Color(0xFF00FF00),
|
||||||
|
child: new Container(),
|
||||||
|
), throwsAssertionError);
|
||||||
|
expect(() => new Title(
|
||||||
|
color: null,
|
||||||
|
child: new Container(),
|
||||||
|
), throwsAssertionError);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should not allow non-opaque color', (WidgetTester tester) async {
|
||||||
|
expect(() => new Title(
|
||||||
|
color: const Color(0),
|
||||||
|
child: new Container(),
|
||||||
|
), throwsAssertionError);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should not pass "null" to setApplicationSwitcherDescription',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final List<MethodCall> log = <MethodCall>[];
|
||||||
|
|
||||||
|
SystemChannels.platform.setMockMethodCallHandler((MethodCall methodCall) async {
|
||||||
|
log.add(methodCall);
|
||||||
|
});
|
||||||
|
|
||||||
|
await tester.pumpWidget(new Title(
|
||||||
|
child: new Container(),
|
||||||
|
color: const Color(0xFF00FF00),
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(log, equals(<MethodCall>[new MethodCall(
|
||||||
|
'SystemChrome.setApplicationSwitcherDescription',
|
||||||
|
<String, dynamic>{'label': '', 'primaryColor': 4278255360},
|
||||||
|
)]));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user