import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';

import 'MyDialog.dart';

part 'my_dialog_controller.g.dart';

@JsonSerializable()
class MyDialogModel {
  //版本id
  String? title_name = "标题"; //标题
  String? message = "消息内容";

  MyDialogModel();

  static MyDialogModel fromJson(Map<String, dynamic> json) =>
      _$MyDialogModelFromJson(json);
  Map<String, dynamic> toJson() => _$MyDialogModelToJson(this);
}

class MyDialogController extends GetControllerEx<MyDialogModel> {
  MyDialogController() {
    attr = GetModel(MyDialogModel()).obs;
  }

  Future<void> showCustomDialog(
    BuildContext context,
    String message, {
    Color? textColor, // 可选参数
  }) async {
    await showDialog(
      barrierColor: Colors.transparent, // 设置上级页面不变暗
      context: context,
      builder: (BuildContext context) {
        return MyDialog(
          message: message,
          seconds: 2,
          textColor: textColor,
        );
      },
    );
  }
}
