unique_widget_test.dart 1013 Bytes
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';
6
import 'package:flutter_test/flutter_test.dart';
7 8

class TestUniqueWidget extends UniqueWidget<TestUniqueWidgetState> {
9
  const TestUniqueWidget({ required super.key });
10 11

  @override
12
  TestUniqueWidgetState createState() => TestUniqueWidgetState();
13 14 15 16
}

class TestUniqueWidgetState extends State<TestUniqueWidget> {
  @override
17
  Widget build(BuildContext context) => Container();
18 19 20 21
}

void main() {
  testWidgets('Unique widget control test', (WidgetTester tester) async {
22
    final TestUniqueWidget widget = TestUniqueWidget(key: GlobalKey<TestUniqueWidgetState>());
23 24 25

    await tester.pumpWidget(widget);

26
    final TestUniqueWidgetState state = widget.currentState!;
27 28 29

    expect(state, isNotNull);

30
    await tester.pumpWidget(Container(child: widget));
31 32 33 34

    expect(widget.currentState, equals(state));
  });
}