modal_barrier.dart 1.82 KB
Newer Older
Adam Barth's avatar
Adam Barth committed
1 2 3 4 5 6
// 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 'framework.dart';
Hixie's avatar
Hixie committed
7
import 'gesture_detector.dart';
Adam Barth's avatar
Adam Barth committed
8
import 'navigator.dart';
9 10
import 'transitions.dart';

11
/// Prevents the user from interacting with widgets behind itself.
Adam Barth's avatar
Adam Barth committed
12
class ModalBarrier extends StatelessComponent {
13 14
  ModalBarrier({
    Key key,
Hixie's avatar
Hixie committed
15
    this.color,
16
    this.dismissable: true
17 18
  }) : super(key: key);

19
  /// If non-null, fill the barrier with this color.
20
  final Color color;
21 22

  /// Whether touching the barrier will pop the current route off the [Navigator].
23
  final bool dismissable;
Adam Barth's avatar
Adam Barth committed
24 25

  Widget build(BuildContext context) {
Hixie's avatar
Hixie committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39
    return new Semantics(
      container: true,
      child: new GestureDetector(
        onTapDown: (Point position) {
          if (dismissable)
            Navigator.pop(context);
        },
        behavior: HitTestBehavior.opaque,
        child: new ConstrainedBox(
          constraints: const BoxConstraints.expand(),
          child: color == null ? null : new DecoratedBox(
            decoration: new BoxDecoration(
              backgroundColor: color
            )
Adam Barth's avatar
Adam Barth committed
40 41
          )
        )
42 43 44 45 46
      )
    );
  }
}

47
/// Prevents the user from interacting with widgets behind itself.
48
class AnimatedModalBarrier extends AnimatedComponent {
49
  AnimatedModalBarrier({
50
    Key key,
51
    Animation<Color> color,
52
    this.dismissable: true
53
  }) : color = color, super(key: key, animation: color);
54

55
  /// If non-null, fill the barrier with this color.
56
  final Animation<Color> color;
57 58

  /// Whether touching the barrier will pop the current route off the [Navigator].
59
  final bool dismissable;
60 61

  Widget build(BuildContext context) {
62 63 64
    return new ModalBarrier(
      color: color.value,
      dismissable: dismissable
65 66 67
    );
  }
}