bench_build_material_checkbox.dart 1.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright 2014 The Flutter 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/material.dart';

import 'recorder.dart';

/// Measures how expensive it is to construct material checkboxes.
///
/// Creates a 10x10 grid of tristate checkboxes.
class BenchBuildMaterialCheckbox extends WidgetBuildRecorder {
  BenchBuildMaterialCheckbox() : super(name: benchmarkName);

  static const String benchmarkName = 'build_material_checkbox';

17
  static bool? _isChecked;
18 19 20

  @override
  Widget createWidget() {
21 22 23 24 25 26 27 28 29
    return Directionality(
      textDirection: TextDirection.ltr,
      child: Material(
        child: Column(
          children: List<Widget>.generate(10, (int i) {
            return _buildRow();
          }),
        ),
      ),
30 31 32 33 34 35
    );
  }

  Row _buildRow() {
    if (_isChecked == null) {
      _isChecked = true;
36
    } else if (_isChecked!) {
37 38 39 40 41 42 43 44 45 46 47
      _isChecked = false;
    } else {
      _isChecked = null;
    }

    return Row(
      children: List<Widget>.generate(10, (int i) {
        return Expanded(
          child: Checkbox(
            value: _isChecked,
            tristate: true,
48
            onChanged: (bool? newValue) {
49 50 51 52 53 54 55 56
              // Intentionally empty.
            },
          ),
        );
      }),
    );
  }
}