Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question/Bug?] 'text'.text.make() causes crash when Text('text') does not #112

Closed
avkonst opened this issue Jun 16, 2021 · 5 comments
Closed
Labels
question Further information is requested

Comments

@avkonst
Copy link

avkonst commented Jun 16, 2021

(Thanks for the package. It does help to develop UI faster)

Describe the bug
If the following is retuned from the widget build function, it crashes with flutter exception:

class SettingsPage extends HookWidget {
    
    SettingsPage({Key? key}) : super(key: key);

    @override
    Widget build(BuildContext context) {
        final user = useUser();
        final theme = useTheme();
        final photoUrl = user?.photoUrl;
        final photoSize = context.screenWidth / 3;
        final photoFallback = CircleAvatar(child: Icon(Icons.person, size: photoSize));
        return Scaffold(
            appBar: AppBar(
                title: "settings".text.uppercase.bold.fontFamily("Brand").make(),
            ),
            body: LayoutBuilder(builder: (context, constraints) {
                return SingleChildScrollView(
                    child: ConstrainedBox(
                        constraints: BoxConstraints(minHeight: constraints.maxHeight),
                        child: IntrinsicHeight(
                            child: Column(
                                mainAxisSize: MainAxisSize.max,
                                crossAxisAlignment: CrossAxisAlignment.stretch,
                                children: [
                                    Expanded(
                                        child: 'top'.text.make().box.height(30).make(),
                                    ),
                                    'header'.text.make().box.height(30).make(),
                                    // comment the following line to get rid of the crash
                                    'header'.text.make(),
                                    Text('header'), // but this one works
                                ]
                            ),
                        )
                    )
                );
            })
        );
    }
}

To Reproduce
Steps to reproduce the behavior:

  1. Render this widget
  2. See error

Expected behavior
I would expect 'header'.text.make() to behave exactly the same as Text('header'). At least not to cause the exception

Console output

/flutter (29236):  └───── ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞══════════════════════
I/flutter (29236): The following assertion was thrown during performLayout():
I/flutter (29236): LayoutBuilder does not support returning intrinsic dimensions.
I/flutter (29236): Calculating the intrinsic dimensions would require running the
I/flutter (29236): layout callback speculatively, which might mutate the live render
I/flutter (29236): object tree.
I/flutter (29236):
I/flutter (29236): The relevant error-causing widget was:
I/flutter (29236):   IntrinsicHeight
I/flutter (29236):
lib\views\page_settings.dart:32
I/flutter (29236):
I/flutter (29236): When the exception was thrown, this was the stack:

I/flutter (29236): #0      _RenderLayoutBuilder._debugThrowIfNotCheckingIntrinsics.<anonymous closure>
package:flutter/…/widgets/layout_builder.dart:390
I/flutter (29236): #1      _RenderLayoutBuilder._debugThrowIfNotCheckingIntrinsics
package:flutter/…/widgets/layout_builder.dart:397
I/flutter (29236): #2      _RenderLayoutBuilder.computeMaxIntrinsicHeight
package:flutter/…/widgets/layout_builder.dart:344
I/flutter (29236): #3      RenderBox._computeIntrinsicDimension.<anonymous closure>
package:flutter/…/rendering/box.dart:1377
I/flutter (29236): #4      _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:311:23)
I/flutter (29236): #5      RenderBox._computeIntrinsicDimension
package:flutter/…/rendering/box.dart:1375
I/flutter (29236): #6      RenderBox.getMaxIntrinsicHeight
package:flutter/…/rendering/box.dart:1747
I/flutter (29236): #7      RenderFlex.computeMaxIntrinsicHeight.<anonymous closure>
package:flutter/…/rendering/flex.dart:635
I/flutter (29236): #8      RenderFlex._getIntrinsicSize
package:flutter/…/rendering/flex.dart:543
I/flutter (29236): #9      RenderFlex.computeMaxIntrinsicHeight
package:flutter/…/rendering/flex.dart:632
I/flutter (29236): #10     RenderBox._computeIntrinsicDimension.<anonymous closure>
package:flutter/…/rendering/box.dart:1377
I/flutter (29236): #11     _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:311:23)
I/flutter (29236): #12     RenderBox._computeIntrinsicDimension
package:flutter/…/rendering/box.dart:1375
....

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6] Ulefone Armor X5
  • OS: [e.g. iOS8.1] Android
  • Browser [e.g. stock browser, safari] n/a
  • Version [e.g. 22] 10

Additional context
Not sure. Just ask if more information is required.

@avkonst avkonst changed the title [Question/Bug?] 'text'.text.make() causes crash when Text('text') does not [Question/Bug?] 'text'.text.make() causes crash when Text('text') does not Jun 16, 2021
@iampawan
Copy link
Owner

iampawan commented Jun 17, 2021

It's an issue with intrinsic widget. Layout builder doesn't support it by default. You can easily fix it by adding .isIntrinsic eg- "text".text.isIntrinsic.make()

@iampawan iampawan added the question Further information is requested label Jun 17, 2021
@avkonst
Copy link
Author

avkonst commented Jun 17, 2021

Why does Text(..) option work? Is not it 'text'.text.make() the same as Text('text')?

@iampawan
Copy link
Owner

It is the same but it uses AutoSizedText to give you a better experience on multi-sized screens and also reduces the chances of overflow issues.

@avkonst
Copy link
Author

avkonst commented Jun 17, 2021 via email

@iampawan
Copy link
Owner

It's just a hack that when you say isIntrinsic, it uses Text rather than AutoSizedText

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants