liuyuqi-dellpc 2 years ago
parent
commit
3c240c06b1
3 changed files with 19 additions and 15 deletions
  1. 6 6
      lib/pages/home_page.dart
  2. 12 9
      lib/views/record_list.dart
  3. 1 0
      pubspec.yaml

+ 6 - 6
lib/pages/home_page.dart

@@ -1,8 +1,8 @@
 import 'dart:io';
 
 import 'package:flutter/material.dart';
+import 'package:flutter_audio_recorder/views/record_list.dart';
 import 'package:flutter_audio_recorder/views/recorder.dart';
-import 'package:flutter_audio_recorder/views/records.dart';
 import 'package:path_provider/path_provider.dart';
 
 class HomePage extends StatefulWidget {
@@ -13,8 +13,8 @@ class HomePage extends StatefulWidget {
 }
 
 class _HomePageState extends State<HomePage> {
-  late Directory? appDir;
-  late List<String>? records;
+  late Directory? appDir; // audio目录
+  late List<String>? records; // audio列表
 
   @override
   Widget build(BuildContext context) {
@@ -24,7 +24,7 @@ class _HomePageState extends State<HomePage> {
         child: InkWell(
           child: const Icon(Icons.mic),
           onTap: () {
-            show(context);
+            showRecord(context);
           },
         ),
       ),
@@ -39,7 +39,7 @@ class _HomePageState extends State<HomePage> {
         children: [
           Expanded(
             flex: 2,
-            child: Records(
+            child: RecordList(
               records: records!,
             ),
           ),
@@ -60,7 +60,7 @@ class _HomePageState extends State<HomePage> {
   }
 
   //底部弹出录音按钮模态框
-  void show(BuildContext context) {
+  void showRecord(BuildContext context) {
     showModalBottomSheet<void>(
       context: context,
       builder: (BuildContext context) {

+ 12 - 9
lib/views/records.dart → lib/views/record_list.dart

@@ -5,21 +5,21 @@ import 'package:flutter/material.dart';
 import 'package:fluttertoast/fluttertoast.dart';
 
 // 录音列表
-class Records extends StatefulWidget {
-  final List<String> records;
+class RecordList extends StatefulWidget {
+  final List<String> records; //audio列表
 
-  const Records({
+  const RecordList({
     Key? key,
     required this.records,
   }) : super(key: key);
 
   @override
-  _RecordsState createState() => _RecordsState();
+  _RecordListState createState() => _RecordListState();
 }
 
-class _RecordsState extends State<Records> {
-  late int _totalTime;
-  late int _currentTime;
+class _RecordListState extends State<RecordList> {
+  late int _totalTime; // 总时常
+  late int _currentTime; // 当前播放位置
   double _percent = 0.0;
   int _selected = -1;
   bool isPlay = false;
@@ -29,6 +29,7 @@ class _RecordsState extends State<Records> {
   Widget build(BuildContext context) {
     return ListView.builder(
       itemCount: widget.records.length,
+      //滚动条
       shrinkWrap: true,
       reverse: true,
       itemBuilder: (BuildContext context, int i) {
@@ -150,6 +151,7 @@ class _RecordsState extends State<Records> {
     );
   }
 
+  // 获取文件创建的时间(根据文件名)
   String _getTime({required String filePath}) {
     String fromPath = filePath.substring(
         filePath.lastIndexOf('/') + 1, filePath.lastIndexOf('.'));
@@ -169,9 +171,10 @@ class _RecordsState extends State<Records> {
   }
 }
 
+/// 按钮
 class _Presso extends StatelessWidget {
-  final IconData ico;
-  final VoidCallback onPressed;
+  final IconData ico; // 图标
+  final VoidCallback onPressed; //执行事件
 
   const _Presso({Key? key, required this.ico, required this.onPressed})
       : super(key: key);

+ 1 - 0
pubspec.yaml

@@ -17,6 +17,7 @@ dependencies:
 
 #  rflutter_alert: ^2.0.2
 #  share: ^2.0.4
+
 dev_dependencies:
   flutter_test:
     sdk: flutter