import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

import 'func_tools.dart';

class Utils {
  ///大陆手机号码11位数，匹配格式：前三位固定格式+后8位任意数
  static bool isPhone(String phone) {
    return RegExp('^1\\d{10}\$').hasMatch(phone);
  }

  static void toast(String? text, BuildContext? context) {
    if (isEmptyString(text)) {
      return;
    }
    Fluttertoast.showToast(
        msg: "$text",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
        // backgroundColor: Colors.red,
        // textColor: Colors.white,
        fontSize: 16.0);
  }



  static Future alert(BuildContext context, String? content, {String? title}) {
    return showCupertinoDialog(
        context: context,
        builder: (BuildContext context) {
          return CupertinoAlertDialog(
            title: Text(title ?? '提示'),
            content: Text(content!),
            actions: <Widget>[
              TextButton(
                child: const Text('确定'),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ],
          );
        });
  }
}