Flutter reported an error when assigning a value, but the data has been obtained

:
movieDetails
images = movieDetails["images"];
large = images["large"];

import "package:flutter/material.dart";
/ / load request tool
import" package:dio/dio.dart";

Dio dio = new Dio ();

/ / Movie details page
class MovieDetail extends StatefulWidget {
MovieDetail ({Key key, @ required this.id, @ required this.title})

  : super(key: key);

final String id;
final String title;
_ MovieDetailState createState () = > _ MovieDetailState ();
}
class _ MovieDetailState extends State < MovieDetail > {
/ / Movie details
var movieDetails = {};
@ override
void initState () {

super.initState();
//
getMovieDetail();

}
/ / get movie details
getMovieDetail () async {

//
print(widget.id);
var response =
    await dio.get("http://api.douban.com/v2/movie/subject/${widget.id}");
var result = response.data;
// 
if (result != null) {
  setState(() {
    movieDetails = result;
  });
}

}

@ override
Widget build (BuildContext context) {

// print("movie------${movieDetail}");
var detail = movieDetails;
var summary="";
var images={};
var large="";
summary = movieDetails["summary"];
images = movieDetails["images"];
// images = ;

/ / print (images);

large = images["large"];
print(large);
var info = movieDetails["year"]+"/"+movieDetails["countries"].join("/")+"/"+movieDetails["genres"].join("/");
return Scaffold(
    appBar: AppBar(
      title: Text(widget.title),
      centerTitle: true,
    ),
    body: Container(
      child: Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(top: 50, bottom: 30),
            color: Color.fromRGBO(23, 45, 74,1),
            child: Align(
              child: Image.network(
               movieDetails["images"]["large"].toString(),
                width: 200.0,
              ),
              alignment: Alignment.center,
            ),
          ),
          Container(
            child: Column(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.only(left: 20, top: 20),
                ),
                Container(
                  padding: EdgeInsets.only(left: 20),
                  child: Row(
                    children: <Widget>[
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: <Widget>[
                            Text(
                              "${widget.title}",
                              softWrap: true,
                              style: TextStyle(
                                  fontSize: 22,
                                  fontWeight: FontWeight.bold),
                            ),
                            Text(
                              info,
                              softWrap: true,
                              style: TextStyle(fontSize: 12),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                )
              ],
            ),
          ),
          Container(
            padding: EdgeInsets.only(left: 20,top: 20),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                Container(
                  child:Text("",
                    softWrap: true,
                    ),
                ),
                Container(
                  padding: EdgeInsets.only(right: 20,top: 10),
                  child: 
                    Text(
                      summary,
                      maxLines: 40,
                      softWrap: true,
                    ),
                  
                )
              ],
            ),
          ),
        ],
      ),
    )
);

}
}

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

May.02,2022
The

request is asynchronous. Before the data is obtained, movieDetails ['images'] is all empty. Of course, an error will be reported. Make a null value judgment


when judging null, display a loading prompt Center (child: CircularProgressIndicator (),) and other asynchronous loading after displaying the normal page

.
Menu