【发布时间】:2021-11-23 19:38:09
【问题描述】:
所以基本上这是我的提供者,我想要的是如何将来自提供者的模型数据存储到共享首选项中,然后如何对其进行解码以将其显示在书签页面中?
class bookmark extends ChangeNotifier{
int _count = 0;
List<bookmarkModel> bookM = [];
void addCount(){
_count++;
notifyListeners();
}
void addItems(bookmarkModel i){
bookM.add(i);
notifyListeners();
}
int get count => _count;
List<bookmarkModel> get bookMList => bookM;
}
这是我的模型:
import 'package:flutter/cupertino.dart';
class bookmarkModel{
String title;
String subtitle;
int num;
bookmarkModel({this.title, this.subtitle, this.num});
bookmarkModel.fromJson(Map<String,dynamic> json) :
title = json['title'],
subtitle = json['sutitle'],
num = json['num'];
Map<String, dynamic> toJson()=>{
'title':title,
'subtitle':subtitle,
'num': num
};
}
【问题讨论】:
标签: flutter dart sharedpreferences provider