mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This patch make grid layout much more flexible. The behavior is factored out into a GridDelegate that's modeled after the custom layout delegates. The patch includes a MaxTileWidthGridDelegate that implements the old behavior and a FixedColumnCountGridDelegate that implements a grid layout with a fixed number of columns. Fixes #1048
30 lines
883 B
Dart
30 lines
883 B
Dart
// 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 'dart:math' as math;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
|
|
import 'lib/solid_color_box.dart';
|
|
|
|
Color randomColor() {
|
|
final List<Color> allColors = [
|
|
Colors.blue,
|
|
Colors.indigo
|
|
].map((p) => p.values).fold([], (a, b) => a..addAll(b));
|
|
final random = new math.Random();
|
|
return allColors[random.nextInt(allColors.length)];
|
|
}
|
|
|
|
RenderBox buildGridExample() {
|
|
List<RenderBox> children = new List<RenderBox>.generate(30, (_) => new RenderSolidColorBox(randomColor()));
|
|
return new RenderGrid(
|
|
children: children,
|
|
delegate: new MaxTileWidthGridDelegate(maxTileWidth: 100.0)
|
|
);
|
|
}
|
|
|
|
main() => new RenderingFlutterBinding(root: buildGridExample());
|