interactive_viewer.constrained.0.dart 1.73 KB
Newer Older
1 2 3 4 5 6
// 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';

7
/// Flutter code sample for [InteractiveViewer.constrained].
8

9
void main() => runApp(const ConstrainedExampleApp());
10

11 12
class ConstrainedExampleApp extends StatelessWidget {
  const ConstrainedExampleApp({super.key});
13 14 15 16 17

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
18 19
        appBar: AppBar(title: const Text('Constrained Sample')),
        body: const ConstrainedExample(),
20 21 22 23 24
      ),
    );
  }
}

25 26
class ConstrainedExample extends StatelessWidget {
  const ConstrainedExample({super.key});
27 28 29

  @override
  Widget build(BuildContext context) {
30 31
    const int rowCount = 48;
    const int columnCount = 6;
32 33

    return InteractiveViewer(
34
      panAxis: PanAxis.aligned,
35 36 37 38
      constrained: false,
      scaleEnabled: false,
      child: Table(
        columnWidths: <int, TableColumnWidth>{
39
          for (int column = 0; column < columnCount; column += 1) column: const FixedColumnWidth(200.0),
40 41
        },
        children: <TableRow>[
42
          for (int row = 0; row < rowCount; row += 1)
43 44
            TableRow(
              children: <Widget>[
45
                for (int column = 0; column < columnCount; column += 1)
46 47
                  Container(
                    height: 26,
48
                    color: row % 2 + column % 2 == 1 ? Colors.white : Colors.grey.withOpacity(0.1),
49 50 51 52 53 54 55 56 57 58 59 60
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: Text('$row x $column'),
                    ),
                  ),
              ],
            ),
        ],
      ),
    );
  }
}