import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('麦克风和音量控制'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: MicrophoneAndVolumeControl(),
),
),
);
}
}
class MicrophoneAndVolumeControl extends StatefulWidget {
@override
_MicrophoneAndVolumeControlState createState() =>
_MicrophoneAndVolumeControlState();
}
class _MicrophoneAndVolumeControlState extends State<MicrophoneAndVolumeControl> {
bool _isMicrophoneOn = true; // 麦克风开关状态
double _volume = 7.0; // 音量值
@override
Widget build(BuildContext context) {
return Column(
children: [
// 麦克风开关部分
Row(
children: [
// 左侧:麦克风图标和描述文本
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'麦克风',
textAlign: TextAlign.left, // 设置文本居中对齐
style: TextStyle(
color: Color(0xff000000), // 文本颜色
fontSize: 14, // 字体大小
fontWeight: FontWeight.w400, // 字体粗细
),
),
SizedBox(height: 10),
Text(
'关闭麦克风后,设备将停止录音,以保护您的隐私。这时,您录制的视频将没有音频。',
maxLines: 3,
overflow:TextOverflow.ellipsis ,
style: TextStyle(
color: Color(0xff767e8b), // 文本颜色
fontSize: 12, // 字体大小
fontWeight: FontWeight.w400, // 字体粗细
),
),
],
),
),
// 右侧:麦克风开关
Switch(
value: _isMicrophoneOn,
onChanged: (bool value) {
setState(() {
_isMicrophoneOn = value;
});
},
),
],
),
SizedBox(height: 20), // 间距
// 音量控制部分
Row(
children: [
// 左侧:音量标签
Text(
'输入音量',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
SizedBox(width: 16), // 间距
// 右侧:音量滑块和值
Expanded(
child: Column(
children: [
Slider(
value: _volume,
min: 0,
max: 10,
divisions: 10,
label: _volume.round().toString(),
onChanged: (double value) {
setState(() {
_volume = value;
});
},
),
Text(
'${_volume.round()}',
style: TextStyle(fontSize: 14),
),
],
),
)
],
),
]);
}
}