feat: add serverchan notify client

This commit is contained in:
Simon Ding
2025-02-13 12:04:51 +08:00
parent 8a4566aee8
commit d44f786f9b
6 changed files with 209 additions and 37 deletions

View File

@@ -84,6 +84,17 @@ class _NotifierState extends ConsumerState<NotifierSettings> {
showBarkNotifierDetails(NotifierData());
},
),
),
SettingsCard(
child: InkWell(
child: const Center(
child: Text("Server酱"),
),
onTap: () {
Navigator.of(context).pop();
showServerChanNotifierDetails(NotifierData());
},
),
)
],
),
@@ -98,10 +109,64 @@ class _NotifierState extends ConsumerState<NotifierSettings> {
return showBarkNotifierDetails(notifier);
case "pushover":
return showPushoverNotifierDetails(notifier);
case "serverchan":
return showServerChanNotifierDetails(notifier);
}
return Future<void>.value();
}
Future<void> showServerChanNotifierDetails(NotifierData notifier) {
final _formKey = GlobalKey<FormBuilderState>();
var body = FormBuilder(
key: _formKey,
initialValue: {
"name": notifier.name,
"enabled": notifier.enabled ?? true,
"key": notifier.settings != null ? notifier.settings!["key"] : "",
},
child: Column(
children: [
const Text("https://sct.ftqq.com/"),
FormBuilderTextField(
name: "name",
decoration: Commons.requiredTextFieldStyle(text: "名称"),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: FormBuilderValidators.required(),
),
FormBuilderTextField(
name: "key",
decoration: Commons.requiredTextFieldStyle(text: "Key"),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: FormBuilderValidators.required(),
),
FormBuilderSwitch(name: "enabled", title: const Text("启用"))
],
),
);
onDelete() async {
return ref.read(notifiersDataProvider.notifier).delete(notifier.id!);
}
onSubmit() async {
if (_formKey.currentState!.saveAndValidate()) {
var values = _formKey.currentState!.value;
return ref.read(notifiersDataProvider.notifier).add(NotifierData(
name: values["name"],
service: "serverchan",
enabled: values["enabled"],
settings: {
"key": values["key"],
}));
} else {
throw "validation_error";
}
}
return showSettingDialog(
context, "Server酱", notifier.id != null, body, onSubmit, onDelete);
}
Future<void> showBarkNotifierDetails(NotifierData notifier) {
final _formKey = GlobalKey<FormBuilderState>();