نمایش نتایج 1 تا 7 از 7

نام تاپیک: Map کردن کلاس

  1. #1
    کاربر دائمی آواتار fakhravari
    تاریخ عضویت
    دی 1388
    محل زندگی
    بوشهر
    سن
    34
    پست
    8,016

    Map کردن کلاس

    با سلام
    https://vatanbgs.com/Api/GetListProductHomePageSelect?IdCustomer=00000000-0000-0000-0000-000000000000

    با post خروجی ببنید
    من چطوری این در فلاتر بتونم map کنم




    این مپ من کار نمیکند

    class HomePageViewMobileModel {

    List<HomePageViewModel> Type1 = new List<HomePageViewModel>();
    List<HomePageViewModel> Type2 = new List<HomePageViewModel>();
    List<HomePageViewModel> Type3 = new List<HomePageViewModel>();
    List<HomePageViewModel> Type4 = new List<HomePageViewModel>();
    List<HomePageViewModel> Type5 = new List<HomePageViewModel>();


    List<SlideShowViewModel> SlideShow = new List<SlideShowViewModel>();




    HomePageViewMobileModel({
    this.Type1 ,
    this.Type2 ,
    this.Type3 ,
    this.Type4 ,
    this.Type5 ,
    this.SlideShow ,
    });


    factory HomePageViewMobileModel.fromJson(Map<String, dynamic> parsedJson){
    return HomePageViewMobileModel(
    Type1: parsedJson['Type1'],
    Type2: parsedJson['Type2'],
    Type3: parsedJson['Type3'],
    Type4: parsedJson['Type4'],
    Type5: parsedJson['Type5'],
    SlideShow: parsedJson['SlideShow'],
    );
    }


    }


    class SlideShowViewModel
    {
    int Id ;
    String Title ;
    String TitleBtnCick ;
    String AddressUrl ;
    String Image ;
    DateTime CreateDate ;
    bool IsActive ;
    String SlideTypeName ;
    int IdTypeSlider ;




    SlideShowViewModel({
    this.Id ,
    this.Title ,
    this.TitleBtnCick ,
    this.AddressUrl ,
    this.Image,
    this.CreateDate ,
    this.IsActive,
    this.SlideTypeName ,
    this.IdTypeSlider
    });


    factory SlideShowViewModel.fromJson(Map<String, dynamic> parsedJson){
    return SlideShowViewModel(
    Id: parsedJson['Id'],
    Title: parsedJson['Title'],
    TitleBtnCick: parsedJson['TitleBtnCick'],
    AddressUrl: parsedJson['AddressUrl'],
    Image: parsedJson['Image'],
    CreateDate: parsedJson['CreateDate'],
    IsActive: parsedJson['IsActive'],
    SlideTypeName: parsedJson['SlideTypeName'],
    IdTypeSlider: parsedJson['IdTypeSlider'],
    );
    }




    }


    class HomePageViewModel
    {
    int Inventory;
    int MaxSelect;
    String NameFa;
    String NameEn;
    String NameEnSlug;
    String ImageName;
    String Title;
    String Alt;
    int TotalPrice;
    int IdTypeDisplay;
    int ValueDisplay;
    int TotalPriceDisplay;
    int Rating;
    int IdProductHomePageType;
    bool IsNewProduct;
    bool IsAuction;
    bool IsSpecial;
    int IdProduct;
    int IdProductInventory;
    int TedadDarBag;
    String HomePageType;




    HomePageViewModel({
    this.Inventory,
    this.MaxSelect,
    this.NameFa,
    this.NameEn,
    this.NameEnSlug,
    this.ImageName,
    this.Title,
    this.Alt,
    this.TotalPrice,
    this.IdTypeDisplay,
    this.ValueDisplay,
    this.TotalPriceDisplay,
    this.Rating,
    this.IdProductHomePageType,
    this.IsNewProduct,
    this.IsAuction,
    this.IsSpecial,
    this.IdProduct,
    this.IdProductInventory,
    this.TedadDarBag,
    this.HomePageType,
    });


    factory HomePageViewModel.fromJson(Map<String, dynamic> parsedJson){
    return HomePageViewModel(


    Inventory: parsedJson['Inventory'],
    MaxSelect: parsedJson['MaxSelect'],
    NameFa: parsedJson['NameFa'],
    NameEn: parsedJson['NameEn'],
    NameEnSlug: parsedJson['NameEnSlug'],
    ImageName: parsedJson['ImageName'],
    Title: parsedJson['Title'],
    Alt: parsedJson['Alt'],
    TotalPrice: parsedJson['TotalPrice'],
    IdTypeDisplay: parsedJson['IdTypeDisplay'],
    ValueDisplay: parsedJson['ValueDisplay'],
    TotalPriceDisplay: parsedJson['TotalPriceDisplay'],
    Rating: parsedJson['Rating'],
    IdProductHomePageType: parsedJson['IdProductHomePageType'],
    IsNewProduct: parsedJson['IsNewProduct'],
    IsAuction: parsedJson['IsAuction'],
    IsSpecial: parsedJson['IsSpecial'],
    IdProduct: parsedJson['IdProduct'],
    IdProductInventory: parsedJson['IdProductInventory'],
    TedadDarBag: parsedJson['TedadDarBag'],
    HomePageType: parsedJson['HomePageType']
    );
    }


    }
    عکس های ضمیمه عکس های ضمیمه

  2. #2
    کاربر دائمی آواتار hharddy
    تاریخ عضویت
    اسفند 1392
    محل زندگی
    تهران
    پست
    383

    نقل قول: Map کردن کلاس

    پیشنهاد میکنم کلاس های مدل و جدا کنید از هم اینجوری مدیریتشون آسون تره

    کلاس type:

    class Types { var inventory; int maxSelect; String nameFa; String nameEn; String nameEnSlug; String imageName; String title; String alt; var totalPrice; var idTypeDisplay; var valueDisplay; var totalPriceDisplay; var rating; var idProductHomePageType; bool isNewProduct; bool isAuction; bool isSpecial; var idProduct; var idProductInventory; var tedadDarBag; String homePageType; var idPageType;
    Types( {this.inventory, this.maxSelect, this.nameFa, this.nameEn, this.nameEnSlug, this.imageName, this.title, this.alt, this.totalPrice, this.idTypeDisplay, this.valueDisplay, this.totalPriceDisplay, this.rating, this.idProductHomePageType, this.isNewProduct, this.isAuction, this.isSpecial, this.idProduct, this.idProductInventory, this.tedadDarBag, this.homePageType, this.idPageType});
    Types.fromJson(Map<String, dynamic> json) { inventory = json['Inventory']; maxSelect = json['MaxSelect']; nameFa = json['NameFa']; nameEn = json['NameEn']; nameEnSlug = json['NameEnSlug']; imageName = json['ImageName']; title = json['Title']; alt = json['Alt']; totalPrice = json['TotalPrice']; idTypeDisplay = json['IdTypeDisplay']; valueDisplay = json['ValueDisplay']; totalPriceDisplay = json['TotalPriceDisplay']; rating = json['Rating']; idProductHomePageType = json['IdProductHomePageType']; isNewProduct = json['IsNewProduct']; isAuction = json['IsAuction']; isSpecial = json['IsSpecial']; idProduct = json['IdProduct']; idProductInventory = json['IdProductInventory']; tedadDarBag = json['TedadDarBag']; homePageType = json['HomePageType']; idPageType = json['IdPageType']; }
    Map<String, dynamic> toJson() { final Map<String, dynamic> data = new Map<String, dynamic>(); data['Inventory'] = this.inventory; data['MaxSelect'] = this.maxSelect; data['NameFa'] = this.nameFa; data['NameEn'] = this.nameEn; data['NameEnSlug'] = this.nameEnSlug; data['ImageName'] = this.imageName; data['Title'] = this.title; data['Alt'] = this.alt; data['TotalPrice'] = this.totalPrice; data['IdTypeDisplay'] = this.idTypeDisplay; data['ValueDisplay'] = this.valueDisplay; data['TotalPriceDisplay'] = this.totalPriceDisplay; data['Rating'] = this.rating; data['IdProductHomePageType'] = this.idProductHomePageType; data['IsNewProduct'] = this.isNewProduct; data['IsAuction'] = this.isAuction; data['IsSpecial'] = this.isSpecial; data['IdProduct'] = this.idProduct; data['IdProductInventory'] = this.idProductInventory; data['TedadDarBag'] = this.tedadDarBag; data['HomePageType'] = this.homePageType; data['IdPageType'] = this.idPageType; return data; }}


    کلاس slide:


    class SlideShow { int id; String title; String titleBtnCick; String addressUrl; String image; String createDate; bool isActive; String slideTypeName; int idTypeSlider;
    SlideShow( {this.id, this.title, this.titleBtnCick, this.addressUrl, this.image, this.createDate, this.isActive, this.slideTypeName, this.idTypeSlider});
    SlideShow.fromJson(Map<String, dynamic> json) { id = json['Id']; title = json['Title']; titleBtnCick = json['TitleBtnCick']; addressUrl = json['AddressUrl']; image = json['Image']; createDate = json['CreateDate']; isActive = json['IsActive']; slideTypeName = json['SlideTypeName']; idTypeSlider = json['IdTypeSlider']; }
    Map<String, dynamic> toJson() { final Map<String, dynamic> data = new Map<String, dynamic>(); data['Id'] = this.id; data['Title'] = this.title; data['TitleBtnCick'] = this.titleBtnCick; data['AddressUrl'] = this.addressUrl; data['Image'] = this.image; data['CreateDate'] = this.createDate; data['IsActive'] = this.isActive; data['SlideTypeName'] = this.slideTypeName; data['IdTypeSlider'] = this.idTypeSlider; return data; }}


    کلاس کلی مدل

    class Test{
    List<Types> type1;List<Types> type2;List<SlideShow> slide; Test(this.type1, this.type2, this.slide);}


    و در نهایت متد دریافت اطلاعات:


    Future<Test> Fetch() async{
    var url ="https://vatanbgs.com/Api/GetListProductHomePageSelect";
    http.Response response = await http.post(url,body:
    {'IdCustomer': '00000000-0000-0000-0000-000000000000'}
    );
    if(response.statusCode ==200){
    print("200");
    Iterable temp1 = json.decode(response.body)['Type1'];
    type1 = temp1.map((model)=> Types.fromJson(model)).toList();
    Iterable temp2 = json.decode(response.body)['Type2'];
    type2 = temp2.map((model)=> Types.fromJson(model)).toList();
    Iterable temp3 = json.decode(response.body)['SlideShow'];
    slide = temp3.map((model)=> SlideShow.fromJson(model)).toList();
    var test = Test(type1,type2,slide);
    print(test.type1[0].title);
    return test;
    }else{
    print("400");
    return null;
    }
    }


    از این بهتر هم میتونید بنویسید.

  3. #3
    کاربر دائمی آواتار fakhravari
    تاریخ عضویت
    دی 1388
    محل زندگی
    بوشهر
    سن
    34
    پست
    8,016

    نقل قول: Map کردن کلاس

    ممنون.
    برای کار با فونت سایز در زامارین فرم من از کلمات Small - Mediom استفاده میکردم. معادل اینها در فلاتر چیست؟

  4. #4
    کاربر دائمی آواتار fakhravari
    تاریخ عضویت
    دی 1388
    محل زندگی
    بوشهر
    سن
    34
    پست
    8,016

    نقل قول: Map کردن کلاس

    از این سایت میشه استفاده کرد
    https://javiercbk.github.io/json_to_dart/

  5. #5
    کاربر دائمی آواتار hharddy
    تاریخ عضویت
    اسفند 1392
    محل زندگی
    تهران
    پست
    383

    نقل قول: Map کردن کلاس

    نقل قول نوشته شده توسط fakhravari مشاهده تاپیک
    ممنون.
    برای کار با فونت سایز در زامارین فرم من از کلمات Small - Mediom استفاده میکردم. معادل اینها در فلاتر چیست؟
    تو فلاتر برای تغییر سایز کلمات کلیدی small و ... نداره باید براساس پیکسل کار کنید.
    Text(    'Hello World!',    style: TextStyle(fontSize: 25),), 

  6. #6
    کاربر دائمی آواتار fakhravari
    تاریخ عضویت
    دی 1388
    محل زندگی
    بوشهر
    سن
    34
    پست
    8,016

    نقل قول: Map کردن کلاس

    نقل قول نوشته شده توسط hharddy مشاهده تاپیک
    تو فلاتر برای تغییر سایز کلمات کلیدی small و ... نداره باید براساس پیکسل کار کنید.
    Text(    'Hello World!',    style: TextStyle(fontSize: 25),), 
    در همه گوشی ها پس مشکلی پیش نمیاد؟

  7. #7
    کاربر دائمی آواتار hharddy
    تاریخ عضویت
    اسفند 1392
    محل زندگی
    تهران
    پست
    383

    نقل قول: Map کردن کلاس

    نقل قول نوشته شده توسط fakhravari مشاهده تاپیک
    در همه گوشی ها پس مشکلی پیش نمیاد؟
    برای حل مشکل میتونید خودتون تقریبا واحد sp یا dp بسازید. به اینصورت سایز متن و در درصدی از ارتفاع صفحه نمایش گوشی ضرب کنید.

     double unitHeightValue = MediaQuery.of(context).size.height * 0.01; double multiplier = 25;
    return Text(
    'Some Text',
    style: TextStyle(
    fontSize: multiplier * unitHeightValue,
    ), );

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •