diegoveloper / flutter_keyboard_actions

MIT License
761 stars 164 forks source link

BoxConstraints forces an infinite height #38

Closed hyperpanthera closed 5 years ago

hyperpanthera commented 5 years ago

I try to implement this: https://pub.dev/packages/keyboard_actions

But I get this error:

I/flutter (30378): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ I/flutter (30378): The following assertion was thrown during performLayout(): I/flutter (30378): BoxConstraints forces an infinite height. I/flutter (30378): These invalid constraints were provided to RenderPadding's layout() function by the following I/flutter (30378): function, which probably computed the invalid constraints in question: I/flutter (30378): RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:259:13) I/flutter (30378): The offending constraints were: I/flutter (30378): BoxConstraints(w=360.0, h=Infinity) I/flutter (30378): I/flutter (30378): When the exception was thrown, this was the stack: I/flutter (30378): #0 BoxConstraints.debugAssertIsValid.<anonymous closure>.throwError (package:flutter/src/rendering/box.dart:507:9) I/flutter (30378): #1 BoxConstraints.debugAssertIsValid.<anonymous closure> (package:flutter/src/rendering/box.dart:550:21) I/flutter (30378): #2 BoxConstraints.debugAssertIsValid (package:flutter/src/rendering/box.dart:554:6)

It occurs when I give FormKeyboardActions() a child, the child is:

Padding -> Row[Expanded->Theme->TextFormField]

The FormKeyboardActions() is a child of Dismissible, Dismissible is a child of SizeTransition, which is a child of Column

diegoveloper commented 5 years ago

Try adding a minimum sample code to reproduce the issue

On Wed, Aug 21, 2019, 4:34 AM hyperpanthera notifications@github.com wrote:

I try to implement this: https://pub.dev/packages/keyboard_actions

But I get this error:

I/flutter (30378): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ I/flutter (30378): The following assertion was thrown during performLayout(): I/flutter (30378): BoxConstraints forces an infinite height. I/flutter (30378): These invalid constraints were provided to RenderPadding's layout() function by the following I/flutter (30378): function, which probably computed the invalid constraints in question: I/flutter (30378): RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:259:13) I/flutter (30378): The offending constraints were: I/flutter (30378): BoxConstraints(w=360.0, h=Infinity) I/flutter (30378): I/flutter (30378): When the exception was thrown, this was the stack: I/flutter (30378): #0 BoxConstraints.debugAssertIsValid..throwError (package:flutter/src/rendering/box.dart:507:9) I/flutter (30378): #1 BoxConstraints.debugAssertIsValid. (package:flutter/src/rendering/box.dart:550:21) I/flutter (30378): #2 BoxConstraints.debugAssertIsValid (package:flutter/src/rendering/box.dart:554:6)

It occurs when I give FormKeyboardActions() a child, the child is:

Padding -> Row[Expanded->Theme->TextFormField]

The FormKeyboardActions() is a child of Dismissible, Dismissible is a child of SizeTransition, which is a child of Column

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_keyboard_actions/issues/38?email_source=notifications&email_token=ABFL3UG66BPTEROFXYY6ATDQFUDZFA5CNFSM4IOEIJA2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HGOWT4A, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFL3UE5N3FB4UVIHRJV363QFUDZFANCNFSM4IOEIJAQ .

hyperpanthera commented 5 years ago

@diegoveloper If I put the FormKeyboardActions() in a SizedBox and give it a fixed height it works, so what is this about? How can I make it dynamic? Thank you.

hyperpanthera commented 5 years ago
import 'package:bookie/app/app_colors.dart';
import 'package:bookie/bloc/transactions/transactions_entry_bloc.dart';
import 'package:bookie/enumeration/app/enumeration_app.dart';
import 'package:bookie/ui/transactions_entry/transactions_entry_table_animated_list_monthly_view.dart';
import 'package:bookie/ui/transactions_entry/transactions_entry_table_animated_list_yearly_view.dart';
import 'package:flutter/material.dart';
import 'package:keyboard_actions/keyboard_actions.dart';

class TransactionsEntryTableAnimatedList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: AnimatedList(
        itemBuilder: (BuildContext context, int index, Animation animation) {
          if (transactionsEntryBloc.dateView == DateView.month) {
            return Column(
              children: <Widget>[
                SizeTransition(
                  axis: Axis.vertical,
                  child: Dismissible(
                    background: Opacity(
                      child: Container(
                        child: Column(
                          children: <Widget>[
                            Divider(height: 0.0),
                            Padding(
                              child: Row(
                                children: <Widget>[
                                  Expanded(
                                    child: Container(),
                                    flex: 150
                                  ),
                                  Expanded(
                                    child: Container(),
                                    flex: 325
                                  ),
                                  Expanded(
                                    child: Container(),
                                    flex: 325
                                  ),
                                  Expanded(
                                    child: Icon(Icons.delete_forever),
                                    flex: 200
                                  )
                                ]
                              ),
                              padding: EdgeInsets.symmetric(
                                horizontal: 8.0,
                                vertical: 4.0
                              )
                            ),
                            Divider(height: 0.0)
                          ]
                        ),
                        color: AppColors.delete,
                      ),
                      opacity: 0.5
                    ),

                    child: SizedBox(
                      child: FormKeyboardActions(
                        autoScroll: false,
                        child: TransactionsEntryTableAnimatedListMonthlyView(
                          entry: transactionsEntryBloc.entries[index],
                          index: index
                        )
                      ),
                      height: 32.0
                    ),

                    direction: DismissDirection.endToStart,
                    resizeDuration: Duration(milliseconds: 500),
                    onDismissed: ((DismissDirection direction) => transactionsEntryBloc.delete(index: index)),
                    key: ValueKey(transactionsEntryBloc.entries[index].id)
                  ),
                  sizeFactor: animation
                ),
                Divider(height: 0.0)
              ]
            );
          }
          else {
            return TransactionsEntryTableAnimatedListYearlyView(transactionsEntryBloc.entries[index]);
          }
        },
        initialItemCount: transactionsEntryBloc.entries.length,
        key: transactionsEntryBloc.animatedListKey
      )
    );
  }
}
hyperpanthera commented 5 years ago

@diegoveloper It doesn't work if I remove SizedBox, but SizedBox breaks my UI.

diegoveloper commented 5 years ago

Maybe it's not about FormKeyboardActions It's about how layout works in flutter

Wed, Aug 21, 2019, 6:20 AM hyperpanthera notifications@github.com wrote:

@diegoveloper https://github.com/diegoveloper If I put the FormKeyboardActions() in a SizedBox and give it a fixed height it works, so what is this about?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_keyboard_actions/issues/38?email_source=notifications&email_token=ABFL3UA5BJ75Y3GVQ6RJY33QFUQGFA5CNFSM4IOEIJA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4ZKPHI#issuecomment-523413405, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFL3UHVQ6AXGPGL2PDSIUDQFUQGFANCNFSM4IOEIJAQ .

hyperpanthera commented 5 years ago

@diegoveloper I added an example.

diegoveloper commented 5 years ago

Try without using keyboard actions code dependencies in your layout and check if it works

On Wed, Aug 21, 2019, 6:25 AM hyperpanthera notifications@github.com wrote:

@diegoveloper https://github.com/diegoveloper I added an example.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_keyboard_actions/issues/38?email_source=notifications&email_token=ABFL3UE4ZFEVU4D3ZSA2Y2LQFUQ3HA5CNFSM4IOEIJA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4ZK4AA#issuecomment-523415040, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFL3UHHGSWSDQFZIFNKNJTQFUQ3HANCNFSM4IOEIJAQ .

hyperpanthera commented 5 years ago

@diegoveloper Yeah my UI works without your library.

If you mean that I should remove FormKeyboardActions.setKeyboardActions(context, formKeyboardActionsConfig(context)); then that doesn't make a difference.

diegoveloper commented 5 years ago

Then try adding a code that I could run here to reproduce the issue. Just a simple example that you can build. One simple file.

On Wed, Aug 21, 2019, 6:28 AM hyperpanthera notifications@github.com wrote:

@diegoveloper https://github.com/diegoveloper Yeah my UI works without your library.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_keyboard_actions/issues/38?email_source=notifications&email_token=ABFL3UB45W3UTJIZ7GVFP6DQFUREZA5CNFSM4IOEIJA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4ZLB4Y#issuecomment-523415795, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFL3UCMA7YDPK7UHMFLIMTQFUREZANCNFSM4IOEIJAQ .

hyperpanthera commented 5 years ago

@diegoveloper Hold on, I will prepare a file.

hyperpanthera commented 5 years ago

@diegoveloper Here we go. I edited the example in your repository.

import 'package:flutter/material.dart';
import 'package:keyboard_actions/keyboard_actions.dart';

// Application entry-point
void main() => runApp(MyApp()); // Toggle this to test in a dialog

class MyApp extends StatefulWidget {
  @override
  MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primarySwatch: Colors.blue),
      home: Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: AppBar(
          title: Text("Keyboard Actions Sample"),
        ),
        body: AnimatedList(
          itemBuilder: (BuildContext context, int index, Animation<double> animation) {
            return FormKeyboardActions(
              child: Page()
            );
          },
          initialItemCount: 50
        ),
      )
    );
  }
}

class Page extends StatefulWidget {
  @override
  PageState createState() => PageState();
}

class PageState extends State<Page> {
  Map<String, FocusNode> nodes = {
    'test': FocusNode()
  };

  @override
  void initState() {
    FormKeyboardActions.setKeyboardActions(context, formKeyboardActionsConfig(context));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Text("blabla"),
        Expanded(
          child: TextField(
            autocorrect: false,
            decoration: InputDecoration(
              border: InputBorder.none,
              contentPadding: EdgeInsets.all(0.0)
            ),
            focusNode: nodes['test'],
            keyboardType: TextInputType.number,
            style: Theme.of(context).textTheme.body1.copyWith(fontSize: 12.0)
          )
        )
      ]
    );
  }

  KeyboardActionsConfig formKeyboardActionsConfig(BuildContext context) {
    return KeyboardActionsConfig(
      actions: [
        KeyboardAction(
          focusNode: nodes['test'],
          displayCloseWidget: false
        ),
      ],
      nextFocus: false
    );
  }
}
hyperpanthera commented 5 years ago

@diegoveloper I edited the file again. Forgot something.

hyperpanthera commented 5 years ago

@diegoveloper Again. It was a minor detail to make it closer to my original file.

diegoveloper commented 5 years ago

Ok give me some hours to check the code, I'm out of my computer now.

On Wed, Aug 21, 2019, 6:55 AM hyperpanthera notifications@github.com wrote:

@diegoveloper https://github.com/diegoveloper Again. It was a minor detail to make it closer to my original file.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_keyboard_actions/issues/38?email_source=notifications&email_token=ABFL3UH6UYHKNHTDITVFLN3QFUUJNA5CNFSM4IOEIJA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4ZM7MI#issuecomment-523423665, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFL3UFYJZFAIGUSVFQOKPLQFUUJNANCNFSM4IOEIJAQ .

hyperpanthera commented 5 years ago

@diegoveloper Thank you!

diegoveloper commented 5 years ago

This fix your issue :

body: FormKeyboardActions(
            child: AnimatedList(
                shrinkWrap: true,
                itemBuilder: (BuildContext context, int index,
                    Animation<double> animation) {
                  return Page();
                },
                initialItemCount: 50),
          ),
        )
hyperpanthera commented 5 years ago

@diegoveloper It doesn't in my original case. Please reopen.

jaysephjw commented 5 years ago

Hey @hyperpanthera , I just created #40. This should fix your issue by fixing the autoScroll flag (since you have it set to false). When not autoscrolling, BottomAreaAvoider (which backs FormKeyboardActions) doesn't add the BoxConstraint that is causing trouble. Let me know if that works.

There should only be one FormKeyboardActions on the screen at a time. You probably want to move it to be a parent of your ListViews, instead of having one wrapping every child.

hyperpanthera commented 5 years ago

@jaysephjw Thanks it works but now it pushes down / adds padding to each row when I click on it. If I use it at the parent of my ListViews then there are no keyboard actions at all. Thus I was forced to use it like on my original example (first code) I posted.