How to fetch Conditional widgets from rest api

25 views
Skip to first unread message

Prashant Nigam

unread,
Feb 7, 2021, 6:38:42 AM2/7/21
to Flutter Development (flutter-dev)

i want to fetch only selected widgets from the rest api like this

showp.shows[index].banner == true but

instant showing selected widgets its will give empty space

latest code

https://pastebin.com/2cm85yzv

suppose there are total 4 list but only 2 will contain banner = true but when i render its show all the 4 widgets


full code with rest api

https://pastebin.com/LYe88Bys

Suzuki Tomohiro

unread,
Feb 7, 2021, 8:40:17 AM2/7/21
to Prashant Nigam, Flutter Development (flutter-dev)
Use if statement with condition in shopw.shows.length.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/cc5c2aeb-b779-4197-a474-7f0739f2619fn%40googlegroups.com.

Suzuki Tomohiro

unread,
Feb 7, 2021, 8:53:46 AM2/7/21
to Flutter Development (flutter-dev)
Please respond to the email thread.

Is “shrinkwrap: true”?

I might have different idea about “empty space”. Please attach the screenshot of the empty space.

On Sun, Feb 7, 2021 at 08:43 36 Prashant Nigam <18bc...@ietdavv.edu.in> wrote:
I will show empty space between them if condition is false

On Sun, Feb 7, 2021, 7:12 PM 36 Prashant Nigam <18bc...@ietdavv.edu.in> wrote:
I already use listview or 

carousel_slider but nothing happens

Prashant Nigam

unread,
Feb 7, 2021, 9:53:20 AM2/7/21
to Flutter Development (flutter-dev)
in this bin, I will share all my code  https://pastebin.com/JkaG0ZaK

in case 2 result in its show totally blank screen 

and in case 1 
Capture.PNG

Prashant Nigam

unread,
Feb 7, 2021, 9:55:35 AM2/7/21
to Flutter Development (flutter-dev)
video_20210207_195028.mp4

Suzuki Tomohiro

unread,
Feb 7, 2021, 10:01:36 AM2/7/21
to Prashant Nigam, Flutter Development (flutter-dev)
The item count property in your code does not take the “banner==true” condition. Please pass only items that match the condition to carousel slider.

itemCount: showp.shows.length,

Prashant Nigam

unread,
Feb 7, 2021, 10:28:14 AM2/7/21
to Flutter Development (flutter-dev)
so that it means it's not possible with the above code?


so finally i use looping statements but this work only asset iimages
Container(
                  height: 200,
                  child: LayoutBuilder(
                    builder: (BuildContext context, BoxConstraints constraints) {
                      for (var i = 0; i < showp.shows.length; i++) {
                        return Container(
                          height: 200,
                          child: CarouselSlider(
                            options: CarouselOptions(viewportFraction: .99, autoPlay: true),
                            items: [
                              BannerWidget(
                                image: showp.shows[i].bannerImage,
                                title: showp.shows[i].showTitle,
                              ),
                            ],
                          ),
                        );
                      }
                      return SizedBox(height: 0, width: 0);
                    },
                  ),
                )

is I use a network then it's through the exception 

// Image.network(
          //   _image,
          //   scale: 1,
          //   fit: BoxFit.cover,
          // ),
          Image(
            image: NetworkImage(_image),
          ),
Capture.PNG

Suzuki Tomohiro

unread,
Feb 7, 2021, 10:56:16 AM2/7/21
to Flutter Development (flutter-dev)
Yes, you need to change code by 1-3 lines.

Create a list that contains items in “showp.shows” that has banner == true.

Whether NetworkImage or AssetImage is irrelevant.

Reply all
Reply to author
Forward
0 new messages