import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:sport/bean/achievement_detail_info.dart';
import 'package:sport/bean/achievement_info.dart';
import 'package:sport/provider/lib/view_state_list_model.dart';
import 'package:sport/services/api/inject_api.dart';

class AchievementInfoModel extends ViewStateListModel with InjectLoginApi {

  final int id;

  AchievementInfoModel(this.id);

  AchievementInfo data;

  AchieveDetailInfo detailData;
  Future<AchievementInfo> getAchievementInfo() async {
    AchievementInfo _achievementInfo = await loginApi.getAchievementInfo();

    if (_achievementInfo.code != 0) {
      // Fluttertoast.showToast(
      //     msg: "${_achievementInfo.msg}",
      //     toastLength: Toast.LENGTH_SHORT,
      //     gravity: ToastGravity.CENTER,
      //     backgroundColor: Colors.white,
      //     textColor: Colors.black,
      //     fontSize: 13.0);
    }
    data = _achievementInfo;
    notifyListeners();
    return _achievementInfo;
  }

  Future<AchieveDetailInfo> getAchieveDetailInfo(int id) async {
    AchieveDetailInfo _achieveDetailInfo =
        await loginApi.getAchieveDetailInfo(id);
    if (_achieveDetailInfo.code != 0) {
      Fluttertoast.showToast(
          msg: "${_achieveDetailInfo.msg}",
          toastLength: Toast.LENGTH_SHORT,
          gravity: ToastGravity.CENTER,
          backgroundColor: Colors.white,
          textColor: Colors.black,
          fontSize: 13.0);
    }
    detailData = _achieveDetailInfo;
    notifyListeners();
    return _achieveDetailInfo;
  }

  @override
  Future<List> loadData() async{
    AchieveDetailInfo _achieveDetailInfo =
        await loginApi.getAchieveDetailInfo(id);
    return [_achieveDetailInfo];
  }
}
