Flutter API Data fetch

0

How to bind my json response to my project ? Can you show me how to convert this data on this site? but i got error

Tried calling: map(Clouser:(Dynamic)=> CampaignSHelList)

Here is my json response:

{
    "Success": {
        "SuccessCode": "S0019",
        "SuccessMessage": "Success.",
        "CompaignShelfList": [
            {
                "CoverImagePath": "https://photogranthtest.s3.ap-south-1.amazonaws.com/uploads/default/images/default_cover.png",
                "ShelfImagePath": "https://photogranthtest.s3.ap-south-1.amazonaws.com/uploads/photographerCampaign/3/shelfImage/3_shelfimage.jpg",
                "CampaignTitle": "Brithday",
                "Date": "28/11/2020",
                "BusinessName": "Wedding Photographer1",
                "PhotographerEmail": "pratap@gmail.com",
                "PhotographerImageLogo": "",
                "PhotographerMobileNumber": "8484007598",
                "PhotographerFullName": "Pratap Adhav",
                "PhotographerWebsite": "https://www.google.com",
                "PhotographerProfilePhoto": "https://photogranthtest.s3.ap-south-1.amazonaws.com/uploads/photographer/6/profile/bob_6731.jpg",
                "PhotographerCampaignId": 3
            },
            {
                "CoverImagePath": "https://photogranthtest.s3.ap-south-1.amazonaws.com/uploads/photographerCampaign/2/coverImage/_coverimage_htc-desire-620g-ds-400x400-imae2zgszqyfk2vx.jpeg",
                "ShelfImagePath": "https://photogranthtest.s3.ap-south-1.amazonaws.com/uploads/photographerCampaign/2/shelfImage/2_shelfimage.jpg",
                "CampaignTitle": "Sunil weds Sunita",
                "Date": "14/02/2021",
                "BusinessName": "Wedding Photographer1",
                "PhotographerEmail": "pratap@gmail.com",
                "PhotographerImageLogo": "",
                "PhotographerMobileNumber": "8484007598",
                "PhotographerFullName": "Pratap Adhav",
                "PhotographerWebsite": "https://www.google.com",
                "PhotographerProfilePhoto": "https://photogranthtest.s3.ap-south-1.amazonaws.com/uploads/photographer/6/profile/bob_6731.jpg",
                "PhotographerCampaignId": 2
            }
        ]
    }
}    

This is my ShelfScreen class:

    import 'package:flutter/material.dart';
    import 'dart:ui';
    import 'dart:convert';
    import 'data/shelfscreendata.dart';
    import 'package:google_fonts/google_fonts.dart';
    import 'constant/constant.dart' as Constants;
    import 'PhotographerWelcomeNote.dart';
    import 'package:http/http.dart' as http;
    import 'Utility/global.dart' as Globals;
    import 'data/errordata.dart';
    import 'data/shelfscreendata.dart';
    import 'data/shelfscreendata.dart';



     class ShelfScreen extends StatefulWidget {
    @override
    _ShelfScreenState createState() => _ShelfScreenState();
  }

     class _ShelfScreenState extends State<ShelfScreen> {
   Future<Success> _futureShelf;


  Future<Success> Shelf() async {
   Map data = {
  "AccessToken": "MjUyLTg1REEyUzMtQURTUzVELUVJNUI0QTIyMTE=",
  "CustomerId": 1
};

final http.Response response = await http.post(
  "http://api.pgapp.in/v1/shelflist",
  headers: <String, String>{
    'Content-Type': 'application/json; charset=UTF-8',
  },
  body: jsonEncode(data),
);
if (response.statusCode == 200) {
  // If the server did return a 201 CREATED response,
  // then parse the JSON.
  return Success.fromJson(json.decode(response.body));
} else {
  // If the server did not return a 201 CREATED response,
  // then throw an exception.
  throw Exception('Failed to load data');
}
}
@override
void initState() {
super.initState();
_futureShelf = Shelf();
}


@override
Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    backgroundColor: const Color(0xfff8f8f8),
    leading: Padding(
      padding: EdgeInsets.only(left: 20),
      child:  Image.asset("assets/logo.png",width: 45,height: 45,),
    ),
    title: Center(
      child: Image.asset("assets/Textimage.png",width: 170,height: 45),
    ),
    actions: <Widget>[
         Padding(
           padding: const EdgeInsets.only(right: 20,top: 10,bottom: 10),
           child: Container(
            height: 8,
            width: 35,
            child: CircleAvatar(
              maxRadius: 20,
              backgroundImage: AssetImage("assets/images/prof.jpg"),
            ),
        ),
         ),

    ],

  ),
  body:  (_futureShelf == null)
      ? Text("No Data found")
      : FutureBuilder<Success>(
    future: _futureShelf,
    builder: (context, snapshot) {
      if (snapshot.hasData) {
        if (snapshot.data.hasError) {
          return Center(
              child: Text("${snapshot.data.Error.ErrorMessage}"));
        } else {
          if (snapshot.data.compaignShelfList.length > 0) {
            return gridimages(
              items: snapshot.data.compaignShelfList,
            );
          } else {
            return Center(child: Text("No Data found"));
          }
        }
      } else if (snapshot.hasError) {
        return Text("${snapshot.error}");
      }
      return Center(child: CircularProgressIndicator());
    },
   )

  );

}
 }
class gridimages extends StatelessWidget {
final List<CompaignShelfList> items;
 gridimages({Key key, this.items});
 @override
 Widget build(BuildContext context) {
 return
   GridView.builder(
      shrinkWrap: false,
      scrollDirection: Axis.vertical,
      gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 1,
        childAspectRatio: 1.200,
        mainAxisSpacing: 1.0,
        crossAxisSpacing: 1.0,

      ),
      itemCount: items.length,
      itemBuilder: (context, int index){
        return CategoriesTile(
          imgUrls: items[index].coverImagePath,
          catagory:items[index].businessName,
          date: items[index].date,
          email: items[index].photographerEmail,
          stduio:items[index].businessName,
        );
    //              Image.asset(Shelflist[index]["text_3"],fit: BoxFit.cover,);
      }
      );

   }
   }



   class CategoriesTile extends StatelessWidget {
   final String imgUrls, catagory , date,email,stduio;

   CategoriesTile({@required this.imgUrls, @required this.catagory,@required this.date,@required 
   this.email,@required this.stduio});

   @override
  Widget build(BuildContext context) {
 return GestureDetector(
  onTap: () {
    Navigator.push(
        context,
        MaterialPageRoute(
            builder: (context) => PhotographerWelcomeNote(
              Coverpic: imgUrls,
            )));
  },
  child: Card(
    semanticContainer: true,
    clipBehavior: Clip.antiAliasWithSaveLayer,
    elevation: 5,
    child: Container(
      margin: EdgeInsets.all(8),
      child:
            Stack(
        children: <Widget>[
          Positioned(
            top: 1,
            left: 1,
            right: 1,
            bottom: 50,
            child: ClipRRect(
                borderRadius: BorderRadius.circular(8),
                child:Image.asset(
                  imgUrls,
                  height: 250,
                  width: 400,
                  fit: BoxFit.cover,
                )
               ),
          ),
          Positioned(
            bottom: 50,
            left: 1,
            right: 1,
        //                width: 400,
            height: 60,
            child: ClipRect(
              child: BackdropFilter(
                filter: ImageFilter.blur(sigmaX: 3, sigmaY: 3),
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.black.withOpacity(0),
                    borderRadius: BorderRadius.circular(8),
                  ),

                ),
              ),
            ),
          ),
         Positioned(
           bottom: 80,
           left: 20,
           child: Container(
                  height: 50,
                  width: 400,
                  alignment: Alignment.bottomLeft,
                  child: Text(
                    catagory ?? "Yo Yo",
                    style: GoogleFonts.nunito(
                      fontSize: 18,
                      color: const Color(0xffffffff),
                      fontWeight: FontWeight.w700,
                      height: 1.7647058823529411,
                    ),
                  )),
         ),
          Positioned(
            left: 20,
            bottom: 60,
            child: Container(
                   height: 30,
                   width: 150,
                alignment: Alignment.bottomLeft,
                          child: Text(
                    date,style: GoogleFonts.nunito(
                  fontSize: 13,
                  color: const Color(0xffffffff),
                  fontWeight: FontWeight.w700,
                  height: 1.7647058823529411,
                ),
                ),
              ),
          ),
                     Positioned(
                   bottom: 20,
                       left: 90,
                       child: Container(
                       height: 23,

                       alignment: Alignment.center,
                         child: Text(
                         stduio,
                             style: GoogleFonts.nunito(
                           fontSize: 18,
                         color: const Color(0xff7f7f7f),
                         fontWeight: FontWeight.w700,
                         )
                       ),
                     ),
                     ),
                      Positioned(
                               bottom: 1,
                                left: 90,
                           child: Container(
                                  height: 20,

                            alignment: Alignment.center,
                            child: Text(
                              email,style: GoogleFonts.nunito(
                              fontSize: 10,
                              color: const Color(0xffb4b4b4),
                              fontWeight: FontWeight.w600,
                            ),
                            ),
                           ),
                      ),
          Positioned(
           bottom: 2,
            left: 10,
            child: Container(
              width: 66.0,
              height: 39.0,
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: const AssetImage(
                      'assets/images/camlogo.jpg'),
                  fit: BoxFit.cover,
                ),
                border: Border.all(
                    width: 1.0, color: const Color(0xffb4b4b4)),
              ),
            ),
          ),
        ],
      ),
    ),
   ),

  );
 }
}
api
flutter
asked on Stack Overflow Nov 13, 2020 by Ah Zeem khatib • edited Nov 13, 2020 by RShpd

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0