|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:sw_app/widgets/recording_database.dart'; |
| 3 | +import 'package:sw_app/widgets/recording_model.dart'; |
| 4 | +import 'package:intl/intl.dart'; |
| 5 | + |
| 6 | +class RecordingStoragePage extends StatefulWidget { |
| 7 | + @override |
| 8 | + _RecordingStoragePageState createState() => _RecordingStoragePageState(); |
| 9 | +} |
| 10 | + |
| 11 | +class _RecordingStoragePageState extends State<RecordingStoragePage> { |
| 12 | + late List<RecordingList> recordingList; |
| 13 | + bool isLoading = false; |
| 14 | + |
| 15 | + @override |
| 16 | + void initState() { |
| 17 | + super.initState(); |
| 18 | + |
| 19 | + refreshNotes(); |
| 20 | + } |
| 21 | + |
| 22 | + @override |
| 23 | + void dispose() { |
| 24 | + super.dispose(); |
| 25 | + } |
| 26 | + |
| 27 | + Future refreshNotes() async { |
| 28 | + setState(() => isLoading = true); |
| 29 | + |
| 30 | + this.recordingList = |
| 31 | + (await RecordingDatabase.instance.readRecordingList())!; |
| 32 | + |
| 33 | + setState(() => isLoading = false); |
| 34 | + } |
| 35 | + |
| 36 | + @override |
| 37 | + Widget build(BuildContext context) { |
| 38 | + var theme = Theme.of(context); |
| 39 | + var style = theme.textTheme.displaySmall!.copyWith(fontSize: 30); |
| 40 | + |
| 41 | + return SingleChildScrollView( |
| 42 | + //physics: AlwaysScrollableScrollPhysics(), |
| 43 | + primary: false, |
| 44 | + child: Column( |
| 45 | + children: [ |
| 46 | + const SizedBox( |
| 47 | + height: 20, |
| 48 | + width: 20, |
| 49 | + ), |
| 50 | + Container( |
| 51 | + //alignment: Alignment.center, |
| 52 | + //padding: const EdgeInsets.all(30), |
| 53 | + width: 380, |
| 54 | + decoration: BoxDecoration( |
| 55 | + borderRadius: BorderRadius.circular(10), |
| 56 | + ), |
| 57 | + child: Row( |
| 58 | + mainAxisAlignment: MainAxisAlignment.spaceAround, |
| 59 | + children: [ |
| 60 | + Text('Recorded Data', textAlign: TextAlign.center, style: style), |
| 61 | + ElevatedButton.icon( |
| 62 | + onPressed: () async { |
| 63 | + await RecordingDatabase.instance.deleteDatabase(); |
| 64 | + setState(() {}); |
| 65 | + }, |
| 66 | + label: Text('Delete all'), |
| 67 | + icon: Icon(Icons.delete), |
| 68 | + style: ElevatedButton.styleFrom(backgroundColor: Colors.red), |
| 69 | + ), |
| 70 | + ], |
| 71 | + ), |
| 72 | + ), |
| 73 | + const SizedBox( |
| 74 | + height: 20, |
| 75 | + width: 20, |
| 76 | + ), |
| 77 | + FutureBuilder<List<RecordingList>?>( |
| 78 | + future: RecordingDatabase.instance.readRecordingList(), |
| 79 | + builder: (context, AsyncSnapshot<List<RecordingList>?> snapshot) { |
| 80 | + if (snapshot.hasError) { |
| 81 | + return Center(child: Text(snapshot.error.toString())); |
| 82 | + } |
| 83 | + if (snapshot.data != null) { |
| 84 | + return ListView.builder( |
| 85 | + physics: NeverScrollableScrollPhysics(), |
| 86 | + shrinkWrap: true, |
| 87 | + itemCount: snapshot.data?.length, |
| 88 | + itemBuilder: (context, index) { |
| 89 | + final item = snapshot.data![index]; |
| 90 | + return ListTile( |
| 91 | + leading: Icon(Icons.edgesensor_high), |
| 92 | + title: Text( |
| 93 | + '''Start time: ${DateFormat('dd-MM-yyyy- – kk:mm').format(item.timeStamp)} |
| 94 | + Duration: ${item.duration} sec'''), |
| 95 | + trailing: IconButton( |
| 96 | + onPressed: () { |
| 97 | + RecordingDatabase.instance.delete(item.id); |
| 98 | + setState(() {}); |
| 99 | + }, |
| 100 | + icon: Icon(Icons.delete)), |
| 101 | + ); |
| 102 | + }, |
| 103 | + ); |
| 104 | + } else { |
| 105 | + return Container( |
| 106 | + height: 300, |
| 107 | + child: const Center( |
| 108 | + child: Text( |
| 109 | + 'No recordings yet', |
| 110 | + style: TextStyle(fontSize: 20), |
| 111 | + ), |
| 112 | + )); |
| 113 | + } |
| 114 | + }, |
| 115 | + ), |
| 116 | + ], |
| 117 | + ), |
| 118 | + ); |
| 119 | + } |
| 120 | +} |
0 commit comments