How can I view the details of an item in a detailed screen - Flutter

后端 未结 2 917
遇见更好的自我
遇见更好的自我 2021-01-26 08:16

I am new to flutter this error is giving me a serious nightmare. I have a card list of items called Anchors. These items are coming from the shared preference file which belongs

相关标签:
2条回答
  • 2021-01-26 08:35

    The problem seems to be here

    detailsPage(value : anchors[i]['Oid'])
    

    You're passing Oid as parameter that is an Int. But look that the constructor for detailsPage

    List value;
    detailsPage({Key key, @required this.value}) : super(key: key);
    

    The parameter value is a List. It's hard for me to know what you're trying to do... but you will need to fix this type mismatch.

    EDIT

    It seems that value parameter should be of type Map<String,dynamic>

    class detailsPage extends StatefulWidget {
        Map<String, dynamic> value;
        
        detailsPage({Key key, @required this.value}) : super(key: key);
    
        @override
        _detailsPageState createState() => _detailsPageState(value);
    }
    
    class _detailsPageState extends State<detailsPage> {
        Map<String, dynamic> value;
        
        _detailsPageState(this.value);
    
        @override
        Widget build(BuildContext context) {
            return Scaffold(
                appBar: AppBar(
                    title: Text("Anchors Details Page"),
                    iconTheme: IconThemeData(color: Colors.white),
                    backgroundColor: Colors.green,
                ),            
                body: Container(
                    child: ListView(
                    children: <Widget>[
                        Text(value['Name']),
                        Text(value['Oid'].toString()),
                        ListView.builder(
                            shrinkWrap: true,
                            itemCount: value['DistributionCentres'].length,
                            //context:context, //it saying the name parameter context is not defined
                            physics: NeverScrollableScrollPhysics(),
                            itemBuilder: (BuildContext context, int i) {
                            return Text(value['DistributionCentres'][i]['Name']);
                            })
                    ],
                    ),
                ),
            );
        }
    }
    

    And then you should do

    detailsPage(value : anchors[i])));
    
    0 讨论(0)
  • first screen onPressed get the index and assigned it to variable, or you can just pass i varibale too,

         onPressed: () {
             Navigator.push(context,new MaterialPageRoute(builder: (context) =>
                  detailsPage(i))); },
    

    In detailed page

        class detailsPage extends StatefulWidget {
            final int selectedIndex;
            detailsPage(this.selectedIndex,{Key key}) : super(key: key);
    
           @override
            _detailsPageState createState() => _detailsPageState();
           }
    

    place that you want to use the previous page passsed index,

        return Text(value[widget.selectedIndex]['DistributionCentres'][i]['Name']);
    

    Hope this will help..

    0 讨论(0)
提交回复
热议问题