goods_detail_provide.dart 899 B

1234567891011121314151617181920212223242526272829303132
  1. import 'dart:convert';
  2. import 'dart:async';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_note/config/service_url.dart';
  5. import 'package:flutter_note/model/goods_detail_model.dart';
  6. import 'package:flutter_note/service/service_method.dart';
  7. class GoodsDetailProvide with ChangeNotifier {
  8. GoodsDetailModel _detail; // 商品详情
  9. int _detailIndex; // 详情页的 tabIndex
  10. GoodsDetailModel get detail => _detail;
  11. int get detailIndex => _detailIndex;
  12. changeDetails(String id) async {
  13. _detail = await getGoodsDetail(id);
  14. notifyListeners();
  15. }
  16. changeIndex(int index) {
  17. _detailIndex = index;
  18. notifyListeners();
  19. }
  20. Future<GoodsDetailModel> getGoodsDetail(String id) async {
  21. var response = await request(servicePath['getGoodDetailById'],
  22. formData: {'goodId': id});
  23. return GoodsDetailModel.fromMap(json.decode(response.data));
  24. }
  25. }