import 'package:flutter/cupertino.dart'; import 'package:project_telephony/utils/headers.dart'; import 'package:provider/provider.dart'; import '../../constants/api.dart'; import '../../model/network/api_client.dart'; import '../../model/network/base_model.dart'; import '../../providers/user_provider.dart'; import '../../utils/toast/cloud_toast.dart'; typedef Callback = Function(bool status); class Centertipsalterwidget extends StatefulWidget { final String title; final String desText; final int id; final Callback callback; const Centertipsalterwidget( {Key? key, required this.desText, required this.title, required this.id, required this.callback}) : super(key: key); @override _CentertipsalterwidgetState createState() => _CentertipsalterwidgetState(); } class _CentertipsalterwidgetState extends State { final userProvider = Provider.of(Get.context!, listen: false); @override Widget build(BuildContext context) { return CupertinoAlertDialog( title: Text(widget.title), content: Column(children: [ SizedBox( height: 10.w, ), Align( alignment: const Alignment(0, 0), child: Text(widget.desText), ) ]), actions: [ CupertinoDialogAction( child: const Text( '取消', style: TextStyle(color: Color(0xFF999999)), ), onPressed: () { widget.callback(false); Navigator.pop(context); }, ), CupertinoDialogAction( child: const Text('确定'), onPressed: () async { BaseModel res = await apiClient.request(API.app.delete, data: { 'id': widget.id, }); if (res.code == 0) { setState(() {}); userProvider.updateUserInfo(); } else { CloudToast.show(res.msg); } widget.callback(true); Navigator.pop(context); }, ) ], ); } }