0

I'm trying to figure out what I'm doing wrong. Shouldn't it never fire that error since it's inside a ListView with vertical scroll?

body: Center(
            child: FutureBuilder<FiveDaysForecast>(
          future: forecast,
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return ListView(scrollDirection: Axis.vertical, children: [
                Container(
                    padding: EdgeInsets.all(30),
                    margin: EdgeInsets.fromLTRB(5, 20, 5, 30),
                    child: Column(
                      children: [
                        Image.network(
                            snapshot.data.getCurrentWeatherImageUrl())],
                    )),
                Container(width: 100, height: 60, child: ListView.builder(
                    scrollDirection: Axis.horizontal,
                    itemBuilder: (context, index) {
                      return Container(
                        width: 70,
                        //height: 70,
                        //padding: EdgeInsets.all(5),
                        margin: EdgeInsets.fromLTRB(5, 10, 5, 10)),
                        child: Column(children: [
                          Image.network(
                              "${snapshot.data.getNextFiveHours()[index].getWeatherImageUrl()}"),
                          Text(
                              "${snapshot.data.getNextFiveHours()[index].dateTime.hour}:00",
                              style: GoogleFonts.roboto(
                                  fontSize: 16, color: Colors.white))
                        ]),
                      );
                    },
                    itemCount: 5),),
              ]);
            }
            if (_cityName == "") {
              return Text("Search a city");
            } else {
              return CircularProgressIndicator();
            }
          },
        )),

I'm trying to create a vertical scrollable app that contains an horizontal list view and a container.

3
  • Have you tried to remove the Center widget from the body, and use it only with CircularProgressIndicator? Commented Dec 20, 2020 at 18:50
  • Same error, I just tried Commented Dec 20, 2020 at 18:58
  • Can you send me a screenshot of the debug console? Commented Dec 20, 2020 at 19:00

1 Answer 1

2

You can try this

body: FutureBuilder<FiveDaysForecast>(
    future: forecast,
    builder: (context, snapshot) {
      return snapshot.hasData ? ListView(scrollDirection: Axis.vertical, children: [
        Container(
          padding: EdgeInsets.all(30),
          margin: EdgeInsets.fromLTRB(5, 20, 5, 30),
          child: Column(
            children: [Image.network(snapshot.data.getCurrentWeatherImageUrl())],
          ),
        ),
        Container(
          width: 100, height: 60,
          child: ListView.builder(
            scrollDirection: Axis.horizontal,
            itemBuilder: (context, index) {
              return Container(
                width: 70,
                //height: 70,
                //padding: EdgeInsets.all(5),
                margin: EdgeInsets.fromLTRB(5, 10, 5, 10),
                child: Column(
                  children: [
                  Expanded(
                    child: Image.network("${snapshot.data.getNextFiveHours()[index].getWeatherImageUrl()}"),
                  ),
                  Text("${snapshot.data.getNextFiveHours()[index].dateTime.hour}:00", style: GoogleFonts.roboto(
                    fontSize: 16,
                    color: Colors.white,
                  )),
              ],),);
            },
            itemCount: 5),),
      ]) : Center(
        child: _cityName.isEmpty ? Text("Search a city") : CircularProgressIndicator(),
      );
    },
  )
Sign up to request clarification or add additional context in comments.

3 Comments

Didn't work. Same error. I tried both editing my code and copy and pasting yours
I have wrapped your Image.network into Expanded widget. Try the new code
It worked! Thank you so much! Can you explain me why I needed to wrap the Image in the Expanded widget?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.