mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add a basic Dialog
The dialog will need many more features to be complete, but this class is a basic skeleton of what we'll need. R=jackson@google.com, jackson@chromium.org Review URL: https://codereview.chromium.org/1189893002.
This commit is contained in:
parent
73d9f88384
commit
252291dc3a
@ -103,6 +103,7 @@ dart_pkg("sdk") {
|
||||
"lib/widgets/basic.dart",
|
||||
"lib/widgets/button_base.dart",
|
||||
"lib/widgets/checkbox.dart",
|
||||
"lib/widgets/dialog.dart",
|
||||
"lib/widgets/drawer.dart",
|
||||
"lib/widgets/drawer_header.dart",
|
||||
"lib/widgets/fixed_height_scrollable.dart",
|
||||
|
||||
53
sdk/lib/widgets/dialog.dart
Normal file
53
sdk/lib/widgets/dialog.dart
Normal file
@ -0,0 +1,53 @@
|
||||
// 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 'basic.dart';
|
||||
import 'material.dart';
|
||||
|
||||
class Dialog extends Component {
|
||||
Dialog({
|
||||
String key,
|
||||
this.title,
|
||||
this.content,
|
||||
this.actions,
|
||||
this.onDismiss
|
||||
}) : super(key: key);
|
||||
|
||||
final Widget title;
|
||||
final Widget content;
|
||||
final Widget actions;
|
||||
final Function onDismiss;
|
||||
|
||||
Widget build() {
|
||||
Container mask = new Container(
|
||||
decoration: const BoxDecoration(
|
||||
backgroundColor: const Color(0x7F000000)));
|
||||
|
||||
List<Widget> children = new List<Widget>();
|
||||
|
||||
if (title != null)
|
||||
children.add(title);
|
||||
|
||||
if (content != null)
|
||||
children.add(content);
|
||||
|
||||
if (actions != null)
|
||||
children.add(content);
|
||||
|
||||
return new Stack([
|
||||
new EventListenerNode(mask, onGestureTap: (_) => onDismiss()),
|
||||
new Center(
|
||||
child: new ConstrainedBox(
|
||||
constraints: new BoxConstraints(minWidth: 280.0),
|
||||
child: new Material(
|
||||
level: 4,
|
||||
child: new ShrinkWrapWidth(
|
||||
child: new Block(children)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
24
tests/widgets/dialog-expected.txt
Normal file
24
tests/widgets/dialog-expected.txt
Normal file
@ -0,0 +1,24 @@
|
||||
CONSOLE: TestRenderView enabled
|
||||
CONSOLE:
|
||||
PAINT FOR FRAME #1 ----------------------------------------------
|
||||
1 | TestDisplayList() constructor: 800.0 x 600.0
|
||||
------------------------------------------------------------------------
|
||||
CONSOLE:
|
||||
PAINT FOR FRAME #2 ----------------------------------------------
|
||||
2 | TestDisplayList() constructor: 800.0 x 600.0
|
||||
2 | paintChild RenderStack at Point(0.0, 0.0)
|
||||
2 | | TestDisplayList() constructor: 800.0 x 600.0
|
||||
2 | | paintChild RenderDecoratedBox at Point(0.0, 0.0)
|
||||
2 | | | TestDisplayList() constructor: 800.0 x 600.0
|
||||
2 | | | drawRect(Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), Paint(Color(0x7f000000)))
|
||||
2 | | paintChild RenderPositionedBox at Point(0.0, 0.0)
|
||||
2 | | | TestDisplayList() constructor: 800.0 x 600.0
|
||||
2 | | | paintChild RenderConstrainedBox at Point(260.0, 284.0)
|
||||
2 | | | | TestDisplayList() constructor: 800.0 x 600.0
|
||||
2 | | | | drawRRect(Instance of 'RRect', Paint(Color(0xfffafafa)))
|
||||
2 | | | | paintChild RenderParagraph at Point(0.0, 0.0)
|
||||
2 | | | | | TestDisplayList() constructor: 800.0 x 600.0
|
||||
2 | | | | paintChild RenderParagraph at Point(0.0, 16.0)
|
||||
2 | | | | | TestDisplayList() constructor: 800.0 x 600.0
|
||||
------------------------------------------------------------------------
|
||||
PAINTED 2 FRAMES
|
||||
21
tests/widgets/dialog.dart
Normal file
21
tests/widgets/dialog.dart
Normal file
@ -0,0 +1,21 @@
|
||||
// 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:sky/widgets/basic.dart';
|
||||
import 'package:sky/widgets/dialog.dart';
|
||||
|
||||
import '../resources/display_list.dart';
|
||||
|
||||
main() async {
|
||||
WidgetTester tester = new WidgetTester();
|
||||
|
||||
await tester.test(() {
|
||||
return new Dialog(
|
||||
title: new Text("I am a title"),
|
||||
content: new Text("I am some content")
|
||||
);
|
||||
});
|
||||
|
||||
await tester.endTest();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user