import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:marking_app/common/mixin/common.dart';
import 'package:marking_app/common/model/common/base_structure_result.dart';
import 'package:marking_app/utils/index.dart';
import 'package:marking_app/utils/request/rest_client.dart';

class UseAnswerForQuestion with CommonMixin {
  ValueNotifier<bool> showAnswer;
  String? answerStr;

  UseAnswerForQuestion._({required this.showAnswer});

  // 工厂构造函数
  factory UseAnswerForQuestion.use() {
    return UseAnswerForQuestion._(showAnswer: useState(false));
  }

  getData({required String questionNum, required int taskId}) async {
    this.answerStr = null;
    RestClient client = await getClient();
    BaseStructureResult<String> result = await client.getAnswer(taskId, questionNum);
    if (result.success) {
      this.answerStr = result.data;
      toPrint(val: this.answerStr);
    }
  }
}
