unique_widget.dart 591 Bytes
Newer Older
1 2 3 4
// 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.

5
import 'framework.dart';
6

7
/// A widget that has exactly one inflated instance in the tree.
8 9
abstract class UniqueWidget<T extends State> extends StatefulWidget {
  UniqueWidget({ GlobalKey key }) : super(key: key) {
10 11
    assert(key != null);
  }
12

Adam Barth's avatar
Adam Barth committed
13
  T createState();
14

15
  /// The state for the unique inflated instance of this widget.
Adam Barth's avatar
Adam Barth committed
16 17 18 19
  T get currentState {
    GlobalKey globalKey = key;
    return globalKey.currentState;
  }
20
}