Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

FLUTTER: " Undefined name 'manSoMi' "

I’m trying to call a final variable name "manSoMi" in AssetImage Widget but it always gets an error. I’ve tried many solutions to solve an error but it always says "Undefined name ‘manSoMi’

import 'package:flutter/material.dart';
import 'package:zeus_app/models/Somiproduct.dart';

class DetailProductCart extends StatefulWidget {
  final SoMiNam manSoMi;
   const DetailProductCart({super.key, required this.manSoMi});
  
  @override
  State<DetailProductCart> createState() => _DetailProductCartState();
}

class _DetailProductCartState extends State<DetailProductCart> {
  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: Colors.white,
      body: ListView(
      padding: EdgeInsets.zero,
      children: <Widget>[
        Container(
                width: size.width,
                height: 500,
                decoration:  BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage(manSoMi.image),
                        fit: BoxFit.cover)),
              ),
       
      ],
    )
  
    );
  }

}

This is a Product class that i want to call it in AssetImage Widget by using the index name "manSoMi.image"

class SoMiNam {
  final String image, title, addColors, price;
  final int id;
  SoMiNam(
      {required this.image,
      required this.title,
      required this.addColors,
      required this.price,
      required this.id});
}

List<SoMiNam> aoSoMi = [
  SoMiNam(
      title: 'Sunflower Polo Tee',
      price: '399.000 đ',
      image: 'assets/images/v1.jpeg',
      addColors: '+3 màu',
      id: 1),
  SoMiNam(
      title: 'Bei Linen Shirt',
      price: '429.000 đ',
      image: 'assets/images/v6.jpeg',
      addColors: '+3 màu',
      id: 2),
  SoMiNam(
      title: 'GodFather Shirt',
      price: '449.000 đ',
      image: 'assets/images/v8.jpeg',
      addColors: '+4 màu',
      id: 3),
  SoMiNam(
      title: 'Felix Shirt',
      price: '449.000 đ',
      image: 'assets/images/FelixShirt.JPG',
      addColors: '+2 màu',
      id: 4),
  SoMiNam(
      title: 'Hemi Shirt',
      price: '419.000 đ',
      image: 'assets/images/HemiShirt.JPG',
      addColors: '+1 màu',
      id: 5),
  SoMiNam(
      title: 'Lala Cuban Shirt',
      price: '449.000 đ',
      image: 'assets/images/LalacubanShirt.JPG',
      addColors: '+2 màu',
      id: 6),
];

This is an error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

You should call widget.manSoMi in order to access your variable in state full widget.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading