下面的代码只是为了显示AlertDialog当按钮被点击在Flutter,我正在寻找的方式来触发设备的警报声时,警报对话框弹出Android和iOS.我试着搜索pub.dev的包或其他网站的相关主题,但没有发现到目前为止。
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Application',
theme: ThemeData(
primarySwatch: Colors.blue,
),
debugShowCheckedModeBanner: false,
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: () {
showAlertDialog(context);
},
child: const Text('Press button'),
);
}
}
showAlertDialog(BuildContext context) {
Widget button = TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.pop(context);
},
);
AlertDialog alert = AlertDialog(
title: const Text("Alert title"),
content: const Text('Alert message.'),
actions: [
button,
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
2条答案
按热度按时间wixjitnu1#
试试ringtone player package。
rwqw0loc2#
使用音频播放器包在打开警报框时播放警报音频--https://pub.dev/packages/audioplayers