I am unable to navigate to detail page from List Tile Page and show retrieved data of the particular item

39 views
Skip to first unread message

shravan kumar Pottala

unread,
Jan 30, 2021, 5:24:16 AM1/30/21
to Flutter Development (flutter-dev)
Hi,
I have posted this query already but nobody is trying to fix my issue.

Atleast please try  again


I have uploaded few text items, image items and pdf documents to firebase database / storage and  and able to retrieve all of them in HomeScreen  i.e Vertical CardsUI list as well as ListTiles  View with one image, one title and one subtitle.


But unable to build DetailView i.e One Singe Item's details instead of  multipleCards and navigate to DetailView page 
on click on any List Tile Item  .

My code for HomeScreen.dart is  as follows

        import 'dart:async';
    import 'dart:io';
    import 'package:firebase_auth/firebase_auth.dart';
    import 'package:firebase_database/firebase_database.dart';
    import 'package:flutter/material.dart';
    import 'package:fluttertoast/fluttertoast.dart';
    import 'package:gadjet_inventory/Form/ListTileFeed.dart';
    import 'package:gadjet_inventory/Form/ListTiles.dart';
    import 'package:gadjet_inventory/Form/RetrievePage.dart';
    import 'package:gadjet_inventory/main.dart';
    import 'package:intl/intl.dart';
    import 'package:gadjet_inventory/Form/Data.dart';
    
    import 'UploadData.dart';
    
    import 'package:pdf_flutter/pdf_flutter.dart';
    // ignore: must_be_immutable
    import 'package:url_launcher/url_launcher.dart';
    
    class HomeScreen extends StatefulWidget {
    
      @override
      _HomeScreenState createState() => _HomeScreenState();
    }
    
    class _HomeScreenState extends State<HomeScreen> {
      List<Data> dataList = [];
      List<bool> favList = [];
      bool searchState = false;
      FirebaseAuth auth = FirebaseAuth.instance;
    
      String get data => null;
    
      @override
      void initState() {
        // TODO: implement initState
        super.initState();
    
        DatabaseReference referenceData = FirebaseDatabase.instance.reference().child("Data");
        referenceData.once().then((DataSnapshot dataSnapShot) {
          dataList.clear();
          favList.clear();
          var keys = dataSnapShot.value.keys;
          var values = dataSnapShot.value;
    
          for (var key in keys) {
    
            Data data = new Data(
                values [key]['imgUrl'],
                values [key]['wcimgUrl'],
                values [key]['wcpdfUrl'],
                values [key]['cattegorrytype'],
                values [key]['companyname'],
               values [key]['modelname'],
                values [key]['seriesname'],
                values [key]['serielnumber'],
                key
              //key is the uploadid
            );
            dataList.add(data);
            auth.currentUser().then((value) {
              DatabaseReference reference = FirebaseDatabase.instance.reference().child("Data").child(key).child("Fav")
                  .child(value.uid).child("state");
              reference.once().then((DataSnapshot snapShot){
                if(snapShot.value!=null){
                  if(snapShot.value=="true"){
                    favList.add(true);
                  }else{
                    favList.add(false);
                  }
                }else{
                  favList.add(false);
                }
              });
            });
    
          }
          Timer(Duration(seconds: 1),(){
            setState(() {
              //
            });
          });
    
    
        });
    
    
      }
    
      int selectedRadioTile;
    
      String get path => null;
    
      String get title => null;
    
      setSelectedRadioTile(int val) {
        setState(() {
          selectedRadioTile = val;
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.lightGreen,
          //Color(0xffffffff),
          appBar: AppBar(
           centerTitle: true,
           backgroundColor: Colors.blue,
            title: new Text("Device Details", style:
            TextStyle(fontSize: 20), textAlign: TextAlign.center),
    
            ),
    
          body: dataList.length == 0
              ? Center(
              child: Text("No Data Available", style: TextStyle(fontSize: 30),))
              : ListView.builder(
              itemCount: dataList.length,
              itemBuilder: (_, index) {
                return CardUI(dataList[index].imgUrl,dataList[index].wcimgUrl, ,dataList[index].wcpdfUrl, dataList[index].cattegorrytype,
                    dataList[index].companyname, dataList[index].modelname,dataList[index].seriesname,                dataList[index].uploadid,index);
              }
          ),
        );
      }
    
    
      Widget CardUI(String imgUrl, String wcimgUrl, String wcpdfUrl, String cattegorrytype, String companyname, String modelname,
          String seriesname      String uploadId,int index) {
        return Card(
          elevation: 7,
          margin: EdgeInsets.all(15),
          //color: Color(0xffff2fc3),
          color:Colors.blueGrey,
          child: Container(
            color: Colors.white,
            margin: EdgeInsets.all(1.5),
            padding: EdgeInsets.all(10),
            child: Column(
              children: <Widget>[
                Image.network(
                  imgUrl != null
                      ? imgUrl
                      : '',
                  width: 500,
                  height: 500,
    
                ),
    
    
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      flex: 1,
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
    
                           child: Text(  "Cattegorry Type:- "
                                 "$cattegorrytype",
    
    
    
    
    
                               style: TextStyle(color: Colors.black),
    
    
                             ),
    
    
                      ),
                    ),
                  ],
                ),
    
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      flex: 1,
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Theme(
                          data: ThemeData(
                            hintColor: Colors.blue,
                          ),
    
                        child: Text(  "Company Name:- "
                            "$companyname",
    
                         style: TextStyle(color: Colors.black),
    
                        ),
                        ),
                      ),
                    ),
                    Expanded(
                      flex: 1,
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Theme(
                          data: ThemeData(
                            hintColor: Colors.blue,
                          ),
    
                          child: Text(  "Model Name:- "
                              "$modelname",
    
    
                            style: TextStyle(color: Colors.black),
    
                      ),
                     ),
                      ),
                    ),
    
                  ],
                ),
    
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      flex: 1,
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Theme(
                          data: ThemeData(
                            hintColor: Colors.blue,
                          ),
    
                          child: Text(  "Series Name:- "
                              "$seriesname",
    
    
                           style: TextStyle(color: Colors.black),
    
    
                          ),
                        ),
                      ),
                    ),
    
                  ],
                ),
    
                RaisedButton(
    
    
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10),
                  ),
    
                  color: Colors.blue,
                  child: Text("Warranty Card",
                    style: TextStyle(fontSize: 18, color: Colors.white),),
                ),
                RadioListTile(
                  value: 1,
                  groupValue: selectedRadioTile,
                  title: Text("PDF"),
                  //subtitle: Text("Upload PDF File"),
                  /*  onChanged: (val) {
                            filePicker(context);
                          },*/
                  activeColor: Colors.red,
              ),
             Padding(padding: EdgeInsets.only(top: 15)),
    
              //  _buildPDF1Field(context),
                PDF.network(
                  wcpdfUrl != null
                      ? wcpdfUrl
                      : '',
    
                  width: 600,
                  height: 1000,     placeHolder: Image.asset("assets/images/pdf.png",
                    height: 600, width: 500),
                ),
                SizedBox(height: 24),
    
    
                RadioListTile(
                  value: 2,
                  groupValue: selectedRadioTile,
                  title: Text("Image"),
                  //subtitle: Text("Upload W Card Image"),
                  /* onChanged: (val) {
                            openWCImagePickerModal(context);
                            //_startWCUpload();
                          },*/
                  activeColor: Colors.blue,
    
    
                ),
    
                Padding(padding: EdgeInsets.only(top: 15)),
    
                Image.network(
                  wcimgUrl != null
                      ? wcimgUrl
                  width: 500,
                  height: 500,
    
               ),
              SizedBox(height: 24),
    
    
    
              ],
            ),
          ),
        );
      }
    
    }.


Now my requirement is to show Detail View of single item  when clciked on it in ListTiles , it should navigate to DetailPage and show me the details of that particular item.


How to build DetailView page ? and Navigate from ListTilePage to that particular DetailPage

shravan kumar Pottala

unread,
Feb 1, 2021, 12:11:55 AM2/1/21
to Flutter Development (flutter-dev)
Cant I navigate to detailpage using HomeScreen.dart file only but by using  naigation with onTap event with dataList[index0.uploadid etc?

shravan kumar Pottala

unread,
Feb 2, 2021, 1:13:31 AM2/2/21
to Flutter Development (flutter-dev)
Achieved this Finally with all your support.
Reply all
Reply to author
Forward
0 new messages