Click here to Skip to main content
15,885,979 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So I've already had a problem with this code before and got some help to fix my error, but I have a new one. So basically I'm waiting for a variable and this variable is not null because when I print it, I can see the value of this variable. The screen returns the fallback values and I don't know why. I have two screens: one for create my variable and the other for all the graphic stuff.

This is the detail screen:
Dart
class DetailScreen extends StatefulWidget {
  const DetailScreen({Key? key, required this.mangaImg, required this.mangaTitle, required this.mangalink}) : super(key: key);
  final String mangaImg,mangaTitle,mangalink;
  @override
  _DetailScreenState createState() => _DetailScreenState();
}

class _DetailScreenState extends State<DetailScreen> {
    String? mangaGenre,mangaStatus,mangaAuthor,mangaDesc;
  List<Map<String,dynamic>>? mangaDetail;
  List<Map<String,dynamic>>? mangaDescList;
  List<Map<String,dynamic>>? mangaChapters;

  Future<void> getMangaInfo() async {
    String  TempBaseurl = widget.mangalink.split(".com")[0] + ".com";
    String TempRoute = widget.mangalink.split(".com")[1];
    final webscraper = WebScraper(TempBaseurl);
    if (await webscraper.loadWebPage(TempRoute)){
     mangaDetail = webscraper.getElement("div.panel-story-info > div.story-info-right > table > tbody > tr > td.table-value", []);
     mangaDescList = webscraper.getElement("div.panel-story-info > div.panel-story-info-description", []);
   }

   mangaGenre  = mangaDetail![3]['title'].toString().trim();
   mangaStatus = mangaDetail![2]['title'].toString().trim();
   mangaAuthor = mangaDetail![1]['title'].toString().trim();
   mangaDesc   = mangaDescList![0]['title'].toString().trim();
   print(mangaDesc);
   print(mangaGenre);
   print(mangaStatus);

  }

    @override

    Future<void> getMangaInfos()async {
    await getMangaInfo();
    }

  @override
  Widget build(BuildContext context) {
    Size screensize = MediaQuery.of(context).size;

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Constants.mygreen,
        title: Text(widget.mangaTitle),
        centerTitle: true,
      ),
      body: Container(
        height: screensize.height,
        width: screensize.width,
        child: SingleChildScrollView(
          child: Column(
            children: [
              MangaInfo(
                mangaImg: widget.mangaImg,
                mangaStatus: mangaStatus??"Error" ,
                mangaAuthor : mangaAuthor??"Error" ,

And this is the graphic screen:

Dart
class MangaInfo extends StatelessWidget {
  const MangaInfo({Key? key,  required this.mangaImg,    required this.mangaStatus,   required this.mangaAuthor}) : super(key: key);
  final String mangaImg, mangaStatus,mangaAuthor;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 300,
      width: double.infinity,

      child: Column(

        children: [
          Expanded(child: Center(child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              Container(height: 170, width: 130,child: Image.network(mangaImg, fit: BoxFit.cover,)
              ),
              Text("By $mangaAuthor - $mangaStatus"
                  , style: const TextStyle(
                fontFamily: "SFProDisplay",
              ))
            ],
          ))),
          const SizedBox(
            height: 10,
          ),
          Container(
            height: 80,
            width: double.infinity,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: const[
                MangaInfoBtn(icon:Icons.play_arrow, title: "Read"),
                MangaInfoBtn(icon:Icons.library_add_check, title: "Favorites"),
                MangaInfoBtn(icon:Icons.list, title: "Chapters"),]

If someone can help me with that I will be really grateful. Thanks!

What I have tried:

At first I change my future into a void, but it was really stupid because it was impossible to await for getMangaInfo()
Posted
Updated 21-Jan-22 6:40am
v2
Comments
wseng 30-Jan-22 7:18am    
which variable prints null?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900