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

Incorrect use of ParentDataWidget. #1

Closed
neutrin0x opened this issue Jul 31, 2020 · 7 comments
Closed

Incorrect use of ParentDataWidget. #1

neutrin0x opened this issue Jul 31, 2020 · 7 comments

Comments

@neutrin0x
Copy link

When I use the widget it says this error:
Incorrect use of ParentDataWidget.

It looks fine and everything seems to work properly but debug console throw that all the time.

@Rodiii
Copy link
Owner

Rodiii commented Jul 31, 2020

Hi @neutrin0x , Could you please post example code that I can reproduce your issue?

@odaynasser
Copy link

odaynasser commented Sep 25, 2020

i have the same issue and this is the code

@override
 Widget build(BuildContext context) {
   return CupertinoPageScaffold(
     child: Column(
       children: [
         SizedBox(
           height: 45,
         ),
         Box(
           child: Column(children: <Widget>[
             Align(
               alignment: Alignment.centerLeft,
               child: Text(
                 'Weight System',
                 style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
               ),
             ),
             SizedBox(
               height: 10,
             ),
             CupertinoRadioChoice(
                 selectedColor: AppColor.selectedMenuItemColor,
                 notSelectedColor: AppColor.lightText,
                 choices: {
                   'kg': 'Kilograms',
                   'lb': 'Pounds',
                 },
                 onChange: (selectedGender) {},
                 initialKeyValue: 'kg')
           ]),
         ),
       ],
     ),
   );
 }

 selectWeight(String weightKey) {
   print(weightKey);
 }

@odaynasser
Copy link

odaynasser commented Sep 25, 2020

this is the error:

Performing hot reload...
Syncing files to device iPhone 11 Pro...

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Flexible(flex: 1) wants to apply ParentData of type FlexParentData to a
RenderObject, which has been set up to accept ParentData of incompatible type WrapParentData.
Usually, this means that the Flexible widget has the wrong ancestor RenderObjectWidget. Typically,
Flexible widgets are placed directly inside Flex widgets.
The offending Flexible is currently placed inside a Wrap widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
  _GestureSemantics ← RawGestureDetector ← GestureDetector ← CupertinoButton ← Flexible ← Wrap ←
CupertinoRadioChoice ← Column ← Padding ← DecoratedBox ← ⋯

Another exception was thrown: Incorrect use of ParentDataWidget.
Reloaded 3 of 918 libraries in 300ms.

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.

The ParentDataWidget Flexible(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type WrapParentData.

Usually, this means that the Flexible widget has the wrong ancestor RenderObjectWidget. Typically, Flexible widgets are placed directly inside Flex widgets.
The offending Flexible is currently placed inside a Wrap widget.

The ownership chain for the RenderObject that received the incompatible parent data was:
  _GestureSemantics ← RawGestureDetector ← GestureDetector ← CupertinoButton ← Flexible ← Wrap ← CupertinoRadioChoice ← Column ← Padding ← DecoratedBox ← ⋯
When the exception was thrown, this was the stack: 
#0      RenderObjectElement._updateParentData.<anonymous closure> (package:flutter/src/widgets/framework.dart:5689:11)
#1      RenderObjectElement._updateParentData (package:flutter/src/widgets/framework.dart:5705:6)
#2      ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:4939:15)
#3      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#4      ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:4942:15)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════════════════════════

@dnsflnv
Copy link
Contributor

dnsflnv commented Sep 30, 2020

Widget buildSelectionButton(dynamic key, String value,
      {bool selected = false}) {
    return Container( // Flexible to Container
        child: CupertinoButton(
            disabledColor:
                selected ? widget.selectedColor : widget.notSelectedColor,
            color: selected ? widget.selectedColor : widget.notSelectedColor,
            padding: const EdgeInsets.all(10.0),
            child: Text(value),
            onPressed: !widget.enabled || selected

@AlexSavinien
Copy link

AlexSavinien commented Dec 3, 2020

Hey there, got the same issue

CupertinoRadioChoice(
      choices: model.paiementTypes,
      onChange: model.setSelectedPaiementType,
      initialKeyValue: model.paiementTypes['cb'],
)
Map<String, String> _paiementTypes = {
    'cb': 'CB',
    'cash': 'Cash',
    'cheque': 'Chéque',
    'amo': 'AMO',
    'virement': 'Virement'
  };
  Map<String, String> get paiementTypes => _paiementTypes;

  String _selectedPaiementType;
  String get selectedPaiment => _selectedPaiementType;
  void setSelectedPaiementType({String newPaiementType}) {
    _selectedPaiementType = newPaiementType;
    print('New selected paiement type : $_selectedPaiementType');
  }

Any solution ?

@odaynasser
Copy link

for those still stuck - there's this lib which i switched to https://pub.dev/packages/toggle_switch

Rodiii pushed a commit that referenced this issue Dec 19, 2020
Dynamic value in choices, changed Flexible to Container #2
@Rodiii
Copy link
Owner

Rodiii commented Dec 19, 2020

Hi all, sorry for the late response.

I just merged the fix by @filonov and pushed it to pub.dev (=> version 1.0.1).
This should fix this issue.

Thanks a lot @filonov!

@Rodiii Rodiii closed this as completed Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants