Home > Blockchain >  Incorrect use of ParentDataWidget Widget Issue
Incorrect use of ParentDataWidget Widget Issue

Time:08-30

@override
  Widget build(BuildContext context) {
    return DefaultTabController(
      initialIndex: 0,
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          actions: [
            Align(
              alignment: Alignment.center,
              child: Text(
                "$energy",
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 25.0,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
            SizedBox(
              height: 10,
              width: 10,
            ),
            SafeArea(child: Stack(
              fit: StackFit.passthrough,

              children: [

                IconButton(
                  onPressed: () {
                    _showRewardedAd();
                  },
                  icon: Icon(
                    Icons.bolt_sharp,
                    size: 40,
                    color: Colors.yellowAccent,
                  ),
                ),
                Positioned(
                  height: 3.0,
                  right: 3.0,
                    child: Icon(Icons.ads_click,size: 20,)),
              ],
            ),),
          ],
          title: const Text('Example'),
          bottom: const TabBar(
            indicatorColor: Colors.grey,
            tabs: <Widget>[
              Tab(
                icon: Icon(Icons.cloud_outlined),
              ),
              Tab(
                icon: Icon(Icons.beach_access_sharp),
              ),
            ],
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            Expanded(
              child: ListView.separated(
                physics: BouncingScrollPhysics(),
                itemCount: 5,
                shrinkWrap: true,
                separatorBuilder: (BuildContext context, int index) =>
                    const Divider(
                  height: 15,
                ),
                itemBuilder: (BuildContext context, int index) {
                  return ListTile(
                    onTap: () {
                      setState(
                        () {
                          Navigator.of(context).push(
                            MaterialPageRoute(
                              builder: (context) {
                                return ConversationPage(index, energy);
                              },
                            ),
                          );
                        },
                      );
                    },
                    leading: CircleAvatar(
                      radius: 30,
                      backgroundImage: AssetImage(charactersRepository
                          .characters[index].circleAvatarImage),
                    ),
                    trailing: Icon(Icons.push_pin),
                    title: Text(
                      charactersRepository.characters[index]
                          .nameWithSurname(),
                      style: TextStyle(
                        fontSize: 15.0,
                      ),
                    ),
                    subtitle: FutureBuilder(
                        future: subTitleTxt(index),
                        builder: (BuildContext context,
                            AsyncSnapshot<String> text) {
                          return Text(text.data ?? "- - -");
                        }),
                  );
                },
              ),
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                PhysicalModel(
                  color: Colors.white30,
                  elevation: 8.0,
                  shadowColor: Colors.purpleAccent,
                  shape: BoxShape.circle,
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Padding(
                        padding: const EdgeInsets.all(5.0),
                        child: CircleAvatar(
                          backgroundColor: Colors.white30,
                          radius: 50,
                          child: Text("Gün $newDay", textDirection: TextDirection.ltr,
                            style: GoogleFonts.breeSerif(color:Colors.black87,fontSize: 25),),
                        ),
                      ),
                      Align(
                        alignment: AlignmentDirectional.topStart,
                        widthFactor:0,
                        heightFactor: 0,
                        child: Padding(
                          padding: EdgeInsets.all(10.0),
                          child: SizedBox(
                            width: 200,
                            height: 100,
                            child: Column(
                              children: [
                                Text("OKUL GAZETESİ",
                                    style: GoogleFonts.pacifico(fontSize: 20)),
                                Text(newsRepository.news[0].newTitle[newDay-1],style: GoogleFonts.courgette(fontSize: 18)),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: Column(
                    children: [
                      Container(
                        decoration: BoxDecoration(
                              image: new DecorationImage(image: new AssetImage("images/bg2.png"), fit: BoxFit.cover,opacity:200)
                        ),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.stretch,
                          children: [
                            Expanded(
                              child: ListView.builder(
                                shrinkWrap: true,
                                reverse: true,
                              itemCount: newLenght,
                              itemBuilder: (BuildContext context, int index) {
                                return ListTile(title: Align(
                                    alignment: Alignment.center,
                                    child: ClipRRect(
                                      borderRadius: BorderRadius.circular(15.0),
                                      child: Container(
                                        padding: EdgeInsets.all(8.0),
                                        decoration: BoxDecoration(
                                          color: Colors.deepPurpleAccent.shade100,
                                        ),
                                        child: Text(newsRepository.news[0].newsSubtitle[index],
                                          style: TextStyle(color: Colors.white),
                                        ),
                                      ),)),);}),),
                            SizedBox(height: 10,),],),
                      ),],),),

              ],
            ),
          ],
        ),
      ),
    );
  }

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 ParentData.

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 RepaintBoundary widget.

CodePudding user response:

try this. use separate UI modules or class for TabBarView carefully, in your code 3 module is there check it.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  const MyHomePage({
    Key? key,
    required this.title,
  }) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter  ;
    });
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            centerTitle: false,
            title: Text(
              "Facilities",
              style: TextStyle(color: Colors.black, fontSize: 20),
            ),
            actions: <Widget>[
              Padding(
                  padding: EdgeInsets.only(right: 20.0),
                  child: GestureDetector(
                    onTap: () {},
                    child: Icon(
                      Icons.search,
                      size: 26.0,
                    ),
                  )),
            ],
            backgroundColor: Colors.white,
            elevation: 0,
            bottom: TabBar(
                unselectedLabelColor: Colors.redAccent,
                indicatorSize: TabBarIndicatorSize.tab,
                indicator: BoxDecoration(
                    gradient: LinearGradient(
                        colors: [Colors.redAccent, Colors.orangeAccent]),
                    borderRadius: BorderRadius.circular(6),
                    color: Colors.redAccent),
                tabs: [
                  Tab(
                icon: Icon(Icons.cloud_outlined),
              ),
              Tab(
                icon: Icon(Icons.beach_access_sharp),
              ),
                ]),
          ),
          body: TabBarView(children: [
            Icon(Icons.apps),// first view
            Icon(Icons.movie),// secound view or you can create separate stafull ot stateless calss
            
        
          ]),
        ));
  }
}

CodePudding user response:

Firstly, you dont need Expanded directly inside TabBarView that is wrapped with ListView.

Also the for the second tab item, seems you like to scroll without PhysicalModel. For the background I am using Stack here.

class TBISSUE extends StatefulWidget {
  TBISSUE({Key? key}) : super(key: key);

  @override
  State<TBISSUE> createState() => _TBISSUEState();
}

class _TBISSUEState extends State<TBISSUE> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      initialIndex: 0,
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          actions: [
            Align(
              alignment: Alignment.center,
              child: Text(
                "energy",
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 25.0,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
            SizedBox(
              height: 10,
              width: 10,
            ),
            SafeArea(
              child: Stack(
                fit: StackFit.passthrough,
                children: [
                  IconButton(
                    onPressed: () {},
                    icon: Icon(
                      Icons.bolt_sharp,
                      size: 40,
                      color: Colors.yellowAccent,
                    ),
                  ),
                  Positioned(
                      height: 3.0,
                      right: 3.0,
                      child: Icon(
                        Icons.ads_click,
                        size: 20,
                      )),
                ],
              ),
            ),
          ],
          title: const Text('Example'),
          bottom: const TabBar(
            indicatorColor: Colors.grey,
            tabs: <Widget>[
              Tab(
                icon: Icon(Icons.cloud_outlined),
              ),
              Tab(
                icon: Icon(Icons.beach_access_sharp),
              ),
            ],
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            ListView.separated(
              physics: BouncingScrollPhysics(),
              itemCount: 52,
              shrinkWrap: true,
              separatorBuilder: (BuildContext context, int index) =>
                  const Divider(
                height: 15,
              ),
              itemBuilder: (BuildContext context, int index) {
                return ListTile(
                  onTap: () {},
                  leading: CircleAvatar(
                    radius: 30,
                    // backgroundImage: AssetImage(charactersRepository
                    //     .characters[index].circleAvatarImage),
                  ),
                  trailing: Icon(Icons.push_pin),
                  subtitle: FutureBuilder(builder:
                      (BuildContext context, AsyncSnapshot<String> text) {
                    return Text(text.data ?? "- - -");
                  }),
                );
              },
            ),

            //second item

            Column(
              children: [
                Align(
                  alignment: Alignment.topLeft,
                  child: PhysicalModel(
                    color: Colors.white30,
                    elevation: 8.0,
                    shadowColor: Colors.purpleAccent,
                    shape: BoxShape.circle,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisSize: MainAxisSize.min,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Padding(
                          padding: const EdgeInsets.all(5.0),
                          child: CircleAvatar(
                            backgroundColor: Colors.white30,
                            radius: 50,
                          ),
                        ),
                        Align(
                          alignment: AlignmentDirectional.topStart,
                          widthFactor: 0,
                          heightFactor: 0,
                          child: Padding(
                            padding: EdgeInsets.all(10.0),
                            child: SizedBox(
                              width: 200,
                              height: 100,
                              child: Column(
                                children: [],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),

                //ListView

                Expanded(
                  child: Stack(
                    children: [
                      Container(
                        color: Colors.cyanAccent,
                      ),
                      ListView.builder(
                          shrinkWrap: true,
                          reverse: true,
                          itemCount: 12,
                          itemBuilder: (BuildContext context, int index) {
                            return SizedBox(
                              width: 200,
                              height: 100,
                              child: ListTile(
                                title: ClipRRect(
                                  borderRadius: BorderRadius.circular(15.0),
                                  child: Container(
                                    // padding: EdgeInsets.all(8.0),
                                    decoration: BoxDecoration(
                                      color: Colors.deepPurpleAccent.shade100,
                                    ),
                                    child: Text(
                                      "",
                                      style: TextStyle(),
                                    ),
                                  ),
                                ),
                              ),
                            );
                          }),
                    ],
                  ),
                ),
                SizedBox(
                  height: 10,
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}

  • Related