Home > Enterprise >  Incorrect use of ParentDataWidget Error is being shown
Incorrect use of ParentDataWidget Error is being shown

Time:11-23

Hello. This is the coding I am currently using to make my todoList app. The screen shows the Expanded widget in a good way, however I keep getting this error that I am not sure how to solve for some reason. Any help is appreciated. Also, if you could provide of better solutions I can do that would be wonderful. Thanks.

class _TodoListScreenState extends State<TodoListScreen> {
  void _addTask(BuildContext context) {
    showModalBottomSheet(
      backgroundColor: const Color(0xFF89ABE3),
      context: context,
      isScrollControlled: true,
      builder: (context) => SingleChildScrollView(
        padding: EdgeInsets.only(
          bottom: MediaQuery.of(context).viewInsets.bottom,
        ),
        child: const AddTaskScreen(),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<TasksBloc, TasksState>(
      builder: (context, state) {
        List<Task> tasksList = state.pendingTasks;
        return Scaffold(
          appBar: HomeScreenAppBar(
            appBarTitle: 'T O D O ',
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => const TimerScreen(),
                ),
              );
            },
            icon: Icons.timer,
          ),
          backgroundColor: const Color(0xFF89ABE3),
          floatingActionButton: FloatingActionButton(
            elevation: 6.0,
            onPressed: () => _addTask(context),
            backgroundColor: const Color(0xFF89ABE3),
            child: const Icon(
              Icons.add,
              color: Color(0xFCF6F5FF),
            ),
          ),
          drawer: const MyDrawer(),
          body: Container(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                const SizedBox(
                  height: 70.0,
                ),
                Padding(
                  padding:
                      const EdgeInsets.only(left: 30, right: 30, bottom: 30),
                  child: Text(
                    'Task Ratio (${state.completedTasks.length} : ${state.pendingTasks.length})',
                    style: const TextStyle(
                      fontStyle: FontStyle.italic,
                      fontSize: 20,
                      fontWeight: FontWeight.bold,
                      fontFamily: 'Source Sans Pro',
                    ),
                  ),
                ),
                Expanded(
                  child: Container(
                    padding: const EdgeInsets.symmetric(horizontal: 20.0),
                    decoration: const BoxDecoration(
                      color: Color(0xFCF6F5FF),
                      borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(20.0),
                        topRight: Radius.circular(20.0),
                      ),
                    ),
                    child: TasksList(tasksList: tasksList),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}

Error Log

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

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

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

The ownership chain for the RenderObject that received the incompatible parent data was:
  RepaintBoundary ← NotificationListener<ScrollNotification> ← GlowingOverscrollIndicator ← Scrollable ← PrimaryScrollController ← ListView ← Expanded ← TasksList ← Padding ← DecoratedBox ← ⋯
When the exception was thrown, this was the stack: 
#0      RenderObjectElement._updateParentData.<anonymous closure> (package:flutter/src/widgets/framework.dart:6042:11)
#1      RenderObjectElement._updateParentData (package:flutter/src/widgets/framework.dart:6059:6)
#2      ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:5258:15)
#3      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
#4      ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:5261:15)
#5      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
#6      ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:5261:15)
#7      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
#8      ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:5261:15)
#9      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
#10     ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:5261:15)
#11     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
#12     ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:5261:15)
#13     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
#14     ParentDataElement._applyParentData (package:flutter/src/widgets/framework.dart:5264:5)
#15     ParentDataElement.notifyClients (package:flutter/src/widgets/framework.dart:5308:5)
#16     ProxyElement.updated (package:flutter/src/widgets/framework.dart:5238:5)
#17     ProxyElement.update (package:flutter/src/widgets/framework.dart:5226:5)
#18     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#19     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#20     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#21     StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#22     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#23     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#24     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#25     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#26     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#27     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#28     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#29     StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#30     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#31     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#32     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#33     ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#34     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#35     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5904:32)
#36     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6460:17)
#37     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#38     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#39     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#40     StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#41     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#42     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#43     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#44     StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#45     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#46     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#47     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#48     ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#49     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#50     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#51     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#52     ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#53     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#54     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5904:32)
#55     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6460:17)
#56     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#57     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#58     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#59     ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#60     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#61     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#62     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#63     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#64     StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#65     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#66     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#67     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#68     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#69     StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#70     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#71     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#72     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#73     ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#74     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#75     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#76     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#77     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#78     StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#79     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#80     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#81     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#82     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#83     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#84     ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#85     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#86     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#87     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#88     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#89     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#90     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#91     StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#92     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#93     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#94     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#95     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#96     StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#97     Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#98     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#99     Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#100    ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#101    Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#102    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#103    Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#104    ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#105    Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#106    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#107    Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#108    ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#109    Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#110    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#111    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#112    Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#113    StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#114    Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#115    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#116    Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#117    ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#118    Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#119    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#120    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#121    Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#122    StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#123    Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#124    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#125    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#126    Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#127    StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#128    Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#129    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#130    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#131    Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#132    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2667:19)
#133    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#134    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:378:5)
#135    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15)
#136    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1104:9)
#137    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1015:5)
#141    _invoke (dart:ui/hooks.dart:150:10)
#142    PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318:5)
#143    _drawFrame (dart:ui/hooks.dart:115:31)
(elided 3 frames from dart:async)
====================================================================================================

task_list

class TasksList extends StatelessWidget {
  const TasksList({
    Key? key,
    required this.tasksList,
  }) : super(key: key);

  final List tasksList;

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: ListView.builder(
        padding: EdgeInsets.only(top: 10),
        itemCount: tasksList.length,
        itemBuilder: (context, index) {
          var task = tasksList[index];
          return TaskTile(task: task);
        },
      ),
    );
  }
}

CodePudding user response:

Expanded or Flexible widgets can only be used inside Row, Column, or Flex. You have wrapped TaskList inside Expanded but its parent is a Container which is causing the error.

CodePudding user response:

You can use width : MediaQuery.of(context).size.width on Container instead Wrapping it in Expanded Widget

  • Related