1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import 'dart:convert';
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:flutter_note/config/service_url.dart';
- import 'package:flutter_note/model/home_page_model.dart';
- import 'package:flutter_note/model/hot_goods_model.dart';
- import 'package:flutter_note/service/service_method.dart';
- class HomeProvide with ChangeNotifier {
- HomePageModel _homeEntity; // 首页显示内容
- List<HotGoodsData> _hotGoodsList = []; // 火爆专区
- int _page = 0;
- bool _showBack = false;
- String _district = '定位失败';
- double _longitude = 115.02932;
- double _latitude = 35.76189;
- HomePageModel get homeEntity => _homeEntity;
- List<HotGoodsData> get hodGoodsList => _hotGoodsList;
- bool get showBack => _showBack;
- String get district => _district;
- double get longitude => _longitude;
- double get latitude => _latitude;
- changeDistrict(String value, double longitude, double latitude) {
- _district = value;
- _longitude = longitude;
- _latitude = latitude;
- notifyListeners();
- }
- initHomeEntity(double lon, double lat) async {
- _homeEntity = await _getHomePageContent(lon, lat);
- notifyListeners();
- }
- initHotGoodsList() async {
- _page = 0;
- var hot = await _getHomePageHots(_page);
- _hotGoodsList.clear();
- _hotGoodsList.addAll(hot.data);
- notifyListeners();
- }
- loadMoreHotGoods() async {
- _page++;
- var moreHot = await _getHomePageHots(_page);
- _hotGoodsList.addAll(moreHot.data);
- notifyListeners();
- }
- enableBack(bool state) {
- _showBack = state;
- notifyListeners();
- }
- Future<HomePageModel> _getHomePageContent(double lon, double lat) async {
- var response = await request(servicePath['homePageContent'],
- formData: {'lon': /*'115.02932'*/ lon, 'lat': /*'35.76189'*/ lat });
- return HomePageModel.fromJson(json.decode(response.data.toString()));
- }
- Future<HotGoodsModel> _getHomePageHots(int page) async {
- var response =
- await request(servicePath['homePageHotPart'], formData: {'page': page});
- return HotGoodsModel.fromJson(json.decode(response.data));
- }
- }
|