Skip to content

MaxColumnWidth and MinColumnWidth return different flex values #131467

@khwgit

Description

@khwgit

Is there an existing issue for this?

Steps to reproduce

  1. Create a MaxColumnWidth or MinColumnWidth with a: FlexColumnWidth(1.0) and b: FixedColumnWidth(100)
  2. See the return of .flex([])

The flex() function of both MaxColumnWidth and MinColumnWidth will ignore aFlex when bFlex is null, which will cause unexpected results. For example, MaxColumnWidth(a, b) and MaxColumnWidth(b, a) have different outputs.

@override
double? flex(Iterable<RenderBox> cells) {
final double? aFlex = a.flex(cells);
if (aFlex == null) {
return b.flex(cells);
}
final double? bFlex = b.flex(cells);
if (bFlex == null) {
return null;
}
return math.max(aFlex, bFlex);
}

@override
double? flex(Iterable<RenderBox> cells) {
final double? aFlex = a.flex(cells);
if (aFlex == null) {
return b.flex(cells);
}
final double? bFlex = b.flex(cells);
if (bFlex == null) {
return null;
}
return math.min(aFlex, bFlex);
}

Expected results

1.0 as a is a FlexColumnWIdth

Actual results

null

Code sample

Code sample
import 'package:flutter/rendering.dart';

void main() {
  const width = MaxColumnWidth(
    FlexColumnWidth(1.0),
    FixedColumnWidth(100),
  );
  print('${width.flex([])}');
}
Flutter code sample
import 'package:flutter/material.dart';

/// Flutter code sample for [Table].

void main() => runApp(const TableExampleApp());

class TableExampleApp extends StatelessWidget {
  const TableExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Table Sample')),
        body: const Column(children: [
          TableExample(
            width: MaxColumnWidth(
              FlexColumnWidth(),
              FixedColumnWidth(100),
            ),
          ),
          Divider(),
          TableExample(
            width: MaxColumnWidth(
              FixedColumnWidth(100),
              FlexColumnWidth(),
            ),
          ),
        ]),
      ),
    );
  }
}

class TableExample extends StatelessWidget {
  const TableExample({
    super.key,
    required this.width,
  });

  final TableColumnWidth width;

  @override
  Widget build(BuildContext context) {
    return Table(
      columnWidths: {
        0: width,
        1: const FixedColumnWidth(120),
      },
      children: [
        TableRow(children: [
          Container(
            height: 64,
            color: Colors.green,
          ),
          Container(
            height: 64,
            color: Colors.red,
          )
        ]),
      ],
    );
  }
}

Screenshots or Video

No response

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.2.1 22D68 darwin-arm64, locale en-HK)
    • Flutter version 3.10.6 on channel stable at /Users/xxx/Development/sdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (2 weeks ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/xxx/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.80.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.68.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.2.1 22D68 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 113.0.5672.126

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions