Add UniqueComponent helper for creating components with unique states

This commit is contained in:
Adam Barth 2015-09-25 15:27:15 -07:00
parent ff5676952e
commit e1b8f0b659
2 changed files with 17 additions and 0 deletions

View File

@ -47,5 +47,6 @@ export 'fn3/theme.dart';
export 'fn3/title.dart';
export 'fn3/tool_bar.dart';
export 'fn3/transitions.dart';
export 'fn3/unique_component.dart';
export 'package:vector_math/vector_math.dart' show Matrix4;

View File

@ -0,0 +1,16 @@
// 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/src/fn3.dart';
abstract class UniqueComponent<T extends State> extends StatefulComponent {
UniqueComponent({ GlobalKey key }) : super(key: key ?? new GlobalKey());
T createState();
T get currentState {
GlobalKey globalKey = key;
return globalKey.currentState;
}
}