Skip to content

Crash when aligning TextField by baseline #24705

Closed

Description

@riposteX

I would like to have a TextField and a button in a Row together, aligned by baseline. This causes a crash due to an unimplemented function in package:flutter/src/material/input_decorator.dart.

import 'package:flutter/material.dart';

void main() => runApp(Main());

class Main extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Attendance',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(),
        body: Row(
          crossAxisAlignment: CrossAxisAlignment.baseline,
          textBaseline: TextBaseline.alphabetic,
          children: [
            Expanded(child:TextField()),
            Container(width: 16.0),
            RaisedButton(child: Text('REFRESH')),
          ],
        ),
      ),
    );
  }
}

Output:

I/flutter (25288): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (25288): The following assertion was thrown during performLayout():
I/flutter (25288): not implemented
I/flutter (25288): 'package:flutter/src/material/input_decorator.dart': Failed assertion: line 966 pos 12: 'false'

flutter doctor -v:

[√] Flutter (Channel beta, v0.11.9, on Microsoft Windows [Version 10.0.17134.407], locale en-US)
    • Flutter version 0.11.9 at C:\Users\Admin\Desktop\flutter
    • Framework revision d48e6e433c (4 days ago), 2018-11-20 22:05:23 -0500
    • Engine revision 5c8147450d
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at C:\Users\Admin\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[√] Android Studio (version 3.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 30.0.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[√] Connected device (1 available)
    • Pixel XL • HT7470204168 • android-arm64 • Android 9 (API 28)

• No issues found!

Activity

  1. zoechi commented on Nov 26, 2018

    @zoechi
    Contributor

    Might be the same underlying cause as #23377

  2. added
    c: crashStack traces logged to the console
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Nov 26, 2018
  3. goderbauer commented on Dec 3, 2018

    @goderbauer
    Member

    The asserting that's triggering is here:

    double computeDistanceToActualBaseline(TextBaseline baseline) {
    assert(false, 'not implemented');
    return 0.0;
    }

    That means @zoechi hunch is correct. I am going to de-dup the issues.

  4. goderbauer commented on Dec 3, 2018

    @goderbauer
    Member

    @HansMuller, who submitted the assert :)

  5. added
    customer: crowdAffects or could affect many people, though not necessarily a specific customer.
    on Dec 3, 2018
  6. HansMuller commented on Dec 3, 2018

    @HansMuller
    Contributor

    That function wasn't implemented because at the time it wasn't possible to. Here are my notes from a year ago, when I was working on it:

    ... I thought this would work:

      double _lineHeight(double width, List<RenderBox> boxes) {
        double aboveBaseline = 0.0;
        double belowBaseline = 0.0;
        for (RenderBox box in boxes) {
          if (box == null)
            continue;
          final double baseline = box.getDistanceToBaseline(TextBaseline.alphabetic);
          aboveBaseline = math.max(baseline, aboveBaseline);
          belowBaseline = math.max(box.getMinIntrinsicWidth(width) - baseline, belowBaseline);
        }
        return aboveBaseline + belowBaseline;
      }

    If fails in a complex assertion due to the call to getDistanceToBaseline(). I assume that it's enforcing this documented limitation:

    Only call this function after calling layout on this box. You are only allowed to call this from the parent of this box during that parent's performLayout or paint functions.

    I noticed this in flex.dart, which should need to do the same baseline-aligned line-height thing:
    // TODO(ianh): Support baseline alignment.

    Apparently this is still an open TODO:
    https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/rendering/flex.dart#L511

  7. bzd2000 commented on Mar 27, 2019

    @bzd2000

    Is this going to be solved?

  8. justinmc commented on Apr 2, 2019

    @justinmc
    Contributor

    @bzd2000 I'm hoping to take a look at this when I get some time. I'm trying to clean up a bunch of TextField related problems.

  9. Chesong-Lee-Hospii commented on Apr 3, 2019

    @Chesong-Lee-Hospii

    @justinmc thanks that would be appreciated. I ran into the same issue on Android Studio with Flutter plugin version 33.3.1 and Dart plugin version 182.5215.

  10. GaryQian commented on Apr 6, 2019

    @GaryQian
    Contributor

    #30069 includes a fix for the assert(false...), and I believe Justin is also working on a more thorough fix for this. Whichever lands first (probably Justin's) will fix this, since my patch may take longer as it is part of a much bigger change.

  11. justinmc commented on Apr 11, 2019

    @justinmc
    Contributor

    This should work now with the above PR.

    @GaryQian FYI that PR includes the 1 commit that I cherry picked from you.

  12. imply-wh commented on May 30, 2019

    @imply-wh

    Is there a solution to this problem?My Flutter current version is 1.5.4

  13. justinmc commented on May 30, 2019

    @justinmc
    Contributor

    This should be fixed as of v1.4.17. If you're seeing it on 1.5.4 then let us know how to reproduce it if you can.

  14. andersonptf-work commented on Jun 19, 2019

    @andersonptf-work

    I'm having the same problem. Here is my code snippet:
    body: SingleChildScrollView( child: Container( margin: EdgeInsets.all(15.1), child: Form( key: _formKey, autovalidate: _autoValidate, child: ListView( children: <Widget>[ ListTile( title: TextFormField( decoration: const InputDecoration(labelText: 'Product Barcode'), keyboardType: TextInputType.text, ), ], ), ), ),
    Runnning on version:
    1.5.4-hotfix.2_ • channel stable • https://github.com/flutter/flutter.git
    Framework • revision 7a4c334 (7 weeks ago) • 2019-04-29 11:05:24 -0700
    Engine • revision 52c7a1e
    Tools • Dart 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

  15. andersonptf-work commented on Jun 19, 2019

    @andersonptf-work

    I'm having the same problem. Here is my code snippet:
    body: SingleChildScrollView( child: Container( margin: EdgeInsets.all(15.1), child: Form( key: _formKey, autovalidate: _autoValidate, child: ListView( children: <Widget>[ ListTile( title: TextFormField( decoration: const InputDecoration(labelText: 'Product Barcode'), keyboardType: TextInputType.text, ), ], ), ), ),
    Runnning on version:
    1.5.4-hotfix.2_ • channel stable • https://github.com/flutter/flutter.git
    Framework • revision 7a4c334 (7 weeks ago) • 2019-04-29 11:05:24 -0700
    Engine • revision 52c7a1e
    Tools • Dart 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

    The problem seems to be the SingleChildScrollView container. After removing it I don't have the problem anymore.

  16. justinmc commented on Jun 19, 2019

    @justinmc
    Contributor

    @andersonptf-work Do you need the SingleChildScrollView? I tried your code and couldn't find anything that looked like a bug. If something seems broken let me know.

  17. github-actions commented on Aug 29, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  18. locked as resolved and limited conversation to collaborators on Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: crashStack traces logged to the consolecustomer: crowdAffects or could affect many people, though not necessarily a specific customer.frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packages

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions