modal_barrier.dart 1.84 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.
12
class ModalBarrier extends StatelessWidget {
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
  @override
Adam Barth's avatar
Adam Barth committed
26
  Widget build(BuildContext context) {
Hixie's avatar
Hixie committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40
    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
41 42
          )
        )
43 44 45 46 47
      )
    );
  }
}

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

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

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

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