bottom_sheet_rebuild_test.dart 1.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// 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:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:test/test.dart';

void main() {
  test('Verify that a BottomSheet can be rebuilt with ScaffoldFeatureController.setState()', () {
    testWidgets((WidgetTester tester) {
      final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
13
      PersistentBottomSheetController<Null> bottomSheet;
14 15 16
      int buildCount = 0;

      tester.pumpWidget(new MaterialApp(
17 18
        routes: <String, WidgetBuilder>{
          '/': (BuildContext context) {
19 20 21 22 23 24 25 26
            return new Scaffold(
              key: scaffoldKey,
              body: new Center(child: new Text('body'))
            );
          }
        }
      ));

27
      bottomSheet = scaffoldKey.currentState.showBottomSheet/*<Null>*/((_) {
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
        return new Builder(
          builder: (_) {
            buildCount += 1;
            return new Container(height: 200.0);
          }
        );
      });

      tester.pump();
      expect(buildCount, equals(1));

      bottomSheet.setState((){ });
      tester.pump();
      expect(buildCount, equals(2));
    });
  });

}