12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import 'dart:async';
- import 'dart:convert';
- import 'package:douyin_demo/model/posts_model.dart';
- import 'package:douyin_demo/widgets/WebRequest.dart';
- import 'package:flutter/material.dart';
- import 'package:http/http.dart' as http;
- class PostsGalleryProvider with ChangeNotifier {
- List<PostsModel> model1 = <PostsModel>[];
- List<PostsModel> model2 = <PostsModel>[];
- double _len1 = 0;
- double _len2 = 0;
- List<PostsModel> posts = <PostsModel>[];
- PostsGalleryProvider() {
- getPosts(0, 0);
- // notifyListeners();
- }
- dispose() {
- super.dispose();
- }
- Future getPosts(orderType, ifRefresh) async {
- Uri url = await WebRequest().generate('posts/getPosts', {
- "openId": "ol_BV4zcyVJaOBtOTD5AfpkFERww",
- "dataFrom": "0",
- "count": "30",
- "refreshTime": DateTime.now().toString(),
- "currentSel": "1",
- "ulo": "0",
- "ula": "0"
- });
- var response = await http.get(url);
- //.then((response) {
- // var post = json.decode(response.body)["result"];
- setGalleryModel(response.body);
- notifyListeners();
- }
- setGalleryModel(String items) {
- var result = <PostsModel>[];
- var posts = json.decode(items)["result"];
- // result.add(posts);
- for (var item in posts) {
- result.add(PostsModel.fromJson(item));
- }
- for (var item in result) {
- if (_len1 <= _len2) {
- item.makerName = "";
- item.picsPath = "";
- item.postsLocation = "";
- item.postsReaded = 0;
- model1.add(item);
- _len1 += item.picsRate;
- } else {
- model2.add(item);
- _len2 += item.picsRate;
- }
- }
- // notifyListeners();
- }
- }
|