Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/register upload style #15

Merged
merged 11 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 2 additions & 32 deletions lib/component_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,37 +238,8 @@ class _RecordingsState extends State<Recordings> {
@override
Widget build(BuildContext context) {
return const Column(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
RecordingPage(),
// const Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
// // getRecorder(),
// SizedBox(height: 20),
// Text(
// 'Previous Recordings:',
// style: TextStyle(
// fontSize: 15,
// ),
// ),
//
// ]),
// FutureBuilder<List<Widget>>(
// future: getAudioplayers(),
// builder: (context, snapshot) {
// if (snapshot.connectionState ==
// ConnectionState.waiting) {
// return const Center(
// child: CircularProgressIndicator(),
// );
// } else if (snapshot.hasError) {
// return Text('Error: ${snapshot.error}');
// } else {
// return Column(
// children: snapshot.data!,
// );
// }
// },
// ),
],
);
}
Expand All @@ -281,7 +252,6 @@ class Actions extends StatelessWidget {
Widget build(BuildContext context) {
return const ComponentGroupDecoration(
children: <Widget>[
// RecordingPage(),
Recordings(),
]);
}
Expand Down Expand Up @@ -2579,9 +2549,9 @@ class ComponentGroupDecoration extends StatelessWidget {
child: Card(
margin: EdgeInsets.zero,
elevation: 0,
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.3),
// color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.3),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 20.0),
padding: const EdgeInsets.symmetric(vertical: 1.0),
child: Center(
widthFactor: 10,
child: Column(
Expand Down
10 changes: 10 additions & 0 deletions lib/const/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ const String isProcessedColumn = "isProcessed";
const String insightsDirPathColumn = "zipPath";
const String audioIdColumn = "audioId";

// names of columns for smaple recording table
const String sampleRecordTable = "sampleRecording";
const String sampleRecordIdColumn = "id";
const String sampleRecordFilePathColumn = "filePath";
const String sampleRecordCommentColumn = "comment";
const String sampleRecordTimestampColumn = "timestamp";
const String sampleRecordIsProcessedColumn = "isProcessed";
const String sampleRecordInsightsDirPathColumn = "zipPath";
const String sampleRecordAudioIdColumn = "audioId";

// consts for network calls
const String baseUrl = "http://52.72.143.117:8000";
const String loginUri = "/auth/login/";
Expand Down
26 changes: 23 additions & 3 deletions lib/db/db_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path_provider/path_provider.dart';
import 'user_models.dart'; // Import your data model
// import 'sample_recording_models.dart'; // Import your data model
import 'package:lang_fe/const/consts.dart';

// Create and manage database from here. Creation of new models need to be registered here.
//
class DatabaseHelper {
static const _databaseName = dbPath;
static const _databaseVersion = 1;
static const _databaseVersion = 2;

Future<Database> get database async {
String documentsDirectory = await getDatabasesPath();
String path = join(documentsDirectory, _databaseName);

return await openDatabase(path,
version: _databaseVersion, onCreate: _onCreate);
version: _databaseVersion, onCreate: _onCreate, onUpgrade: _onUpgrade);
}

Future _onCreate(Database db, int version) async {
print('version: $version');
await db.execute('''
create table $userTable (
$userIdColumn INTEGER PRIMARY KEY AUTOINCREMENT,
Expand All @@ -41,4 +43,22 @@ class DatabaseHelper {
);
''');
}
}

Future<void> _onUpgrade(Database db, int oldVersion, int newVersion) async {
print('oldVersion: $oldVersion ; newVersion: $newVersion');
if (oldVersion == 1) {
await db.execute('''
create table $sampleRecordTable (
$sampleRecordIdColumn INTEGER PRIMARY KEY AUTOINCREMENT,
$sampleRecordFilePathColumn TEXT NOT NULL,
$sampleRecordCommentColumn TEXT NOT NULL,
$sampleRecordIsProcessedColumn INTEGER NOT NULL DEFAULT 0,
$sampleRecordInsightsDirPathColumn TEXT NOT NULL,
$sampleRecordTimestampColumn TEXT NOT NULL,
$sampleRecordAudioIdColumn INTEGER NOT NULL
);
''');
print("Table new_table created during upgrade.");
}
}
}
2 changes: 1 addition & 1 deletion lib/db/recording_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AudioRecordingProvider {

Future<List<AudioRecord>> getAll() async {
Database db = await DatabaseHelper().database;
List<Map<String, Object?>> maps = await db.query(recordingTable);
List<Map<String, Object?>> maps = await db.query(recordingTable, orderBy: 'id DESC');
List<AudioRecord> recordings = [];
for (var map in maps) {
recordings.add(AudioRecord(
Expand Down
80 changes: 80 additions & 0 deletions lib/db/sample_recording_models.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import 'package:flutter/foundation.dart';
import 'package:sqflite/sqflite.dart';

import '../const/consts.dart';
import 'db_helper.dart';

class AudioSampleRecord {
int? id;
final String path;
final String comment;
final String timestamp;
final int isProcessed;
final String insightsDirPath;
int? audioId;

AudioSampleRecord({
this.id,
required this.path,
required this.comment,
required this.timestamp,
required this.isProcessed,
required this.insightsDirPath,
this.audioId,
});

Map<String, Object?> toMap() {
var map = <String, Object?>{
sampleRecordIdColumn: id,
sampleRecordFilePathColumn: path,
sampleRecordCommentColumn: comment,
sampleRecordTimestampColumn: timestamp,
sampleRecordIsProcessedColumn: isProcessed,
sampleRecordInsightsDirPathColumn: insightsDirPath,
sampleRecordAudioIdColumn: audioId,
};

return map;
}
}

class AudioSampleRecordingProvider {
AudioSampleRecordingProvider();

Future<AudioSampleRecord?> createRecording(
String filePath,String comment,String length,String timestamp, int audioId) async {
Database db = await DatabaseHelper().database;
AudioSampleRecord recording = AudioSampleRecord(
path: filePath,
comment: comment,
isProcessed: 0,
insightsDirPath: '',
timestamp: timestamp,
audioId: audioId,
);
print(recording.toMap());
var r = await db.insert(sampleRecordTable, recording.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace);
recording.id = r;
return recording;
}

Future<List<AudioSampleRecord>> getAll() async {
Database db = await DatabaseHelper().database;
List<Map<String, Object?>> maps = await db.query(sampleRecordTable);
List<AudioSampleRecord> recordings = [];
for (var map in maps) {
recordings.add(AudioSampleRecord(
id: map[sampleRecordIdColumn] as int,
path: map[sampleRecordFilePathColumn] as String,
comment: map[sampleRecordCommentColumn] as String,
isProcessed: map[sampleRecordIsProcessedColumn] as int,
insightsDirPath: map[sampleRecordInsightsDirPathColumn] as String,
timestamp: map[sampleRecordTimestampColumn] as String,
audioId: maps[0][sampleRecordAudioIdColumn] as int,
));
}

return recordings;
}
}
144 changes: 100 additions & 44 deletions lib/pages/audio_recorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:record/record.dart';

import 'platform/audio_recorder_platform.dart';

class Recorder extends StatefulWidget {
final Future<void> Function(String path) onStop;
final String waitToText;
final bool isSampleRecord;

const Recorder({super.key, required this.onStop});
const Recorder({super.key, required this.onStop, required this.waitToText, required this.isSampleRecord});

@override
State<Recorder> createState() => _RecorderState();
Expand Down Expand Up @@ -134,22 +135,65 @@ class _RecorderState extends State<Recorder> with AudioRecorderMixin {

@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_buildRecordStopControl(),
// if (_textBoxIsVisible) const Padding(
// padding: EdgeInsets.all(8.0),
// child: MacosTextField(
// placeholder: "Enter your text here",
// maxLines: 1,
// ),
// ),
const SizedBox(width: 20),
_buildPauseResumeControl(),
const SizedBox(width: 20),
_buildText(),
],
return Container(
// color: Colors.red,
decoration: BoxDecoration(
// color:Theme.of(context).primaryColor.withOpacity(0.1),
// border: Border.all(color: Colors.red, width: 2.0),
// borderRadius: BorderRadius.vertical(
// top: Radius.circular(8.0),
// bottom: Radius.circular(8.0),
// ),
),
padding: widget.isSampleRecord ? ((_recordState != RecordState.stop) ? EdgeInsets.fromLTRB(24, 160, 24, 20) : EdgeInsets.fromLTRB(24, 80, 24, 20)) : EdgeInsets.fromLTRB(24, 20, 24, 0),
child: (_recordState != RecordState.stop) ? Container(
padding: EdgeInsets.only(bottom: 12.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children:[
Padding(
padding: widget.isSampleRecord ? EdgeInsets.only(bottom: 24.0) : EdgeInsets.only(bottom: 12.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[
_buildRecordStopControl(Theme.of(context).primaryColor.withOpacity(0.5),widget.isSampleRecord),
SizedBox(width: 8),
_buildPauseResumeControl(),
SizedBox(width: 8),
_buildTimer(),
]
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[
_buildText('DURING RECORDING'),
]
)
]
)
): Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children:[
Padding(
padding: widget.isSampleRecord ? EdgeInsets.only(bottom: 24.0) : EdgeInsets.only(bottom: 12.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[
_buildRecordStopControl(Theme.of(context).primaryColor.withOpacity(0.5),widget.isSampleRecord),
]
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[
_buildText(widget.waitToText),
]
)
]
)
);
}

Expand All @@ -162,44 +206,56 @@ class _RecorderState extends State<Recorder> with AudioRecorderMixin {
super.dispose();
}

Widget _buildRecordStopControl() {

return IconButton(
// isSelected: playProgressIndicator,
selectedIcon: const Icon(Icons.pause),
icon: (_recordState != RecordState.stop)? const Icon(Icons.stop): const Icon(Icons.mic),
onPressed: () {
setState(() {
(_recordState != RecordState.stop) ? _stop() : _start();
});
},
Widget _buildRecordStopControl(Color _color, bool isSampleRecord) {
debugPrint('isSampleRecord: $isSampleRecord');

return Container(
width: (!isSampleRecord || _recordState != RecordState.stop) ? 60.0 : 120.0,
height: (!isSampleRecord || _recordState != RecordState.stop) ? 60.0 : 120.0,
decoration: BoxDecoration(
color: (_recordState != RecordState.stop) ? Colors.black.withOpacity(0.05) : _color, // 设置背景色
borderRadius: BorderRadius.circular((_recordState != RecordState.stop) ? 40.0 : 60.0), // 设置圆角
),
child: IconButton(
selectedIcon: const Icon(Icons.pause, size: 80.0 ),
icon: (_recordState != RecordState.stop)? (isSampleRecord ? Icon(Icons.stop, size: 40.0, color: Color(0x806750a4)) : Icon(Icons.stop, size: 40.0, color: Color(0x806750a4) )): (isSampleRecord ? Icon(Icons.mic, size: 80.0, color: Colors.white) : Icon(Icons.mic, size: 40.0, color: Colors.white)),
onPressed: () {
setState(() {
(_recordState != RecordState.stop) ? _stop() : _start();
});
},
)
);

}

Widget _buildPauseResumeControl() {
if (_recordState == RecordState.stop) {
return const SizedBox.shrink();
}

return IconButton(
// isSelected: playProgressIndicator,
selectedIcon: const Icon(Icons.pause),
icon: (_recordState == RecordState.record)? const Icon(Icons.pause): const Icon(Icons.play_arrow),
onPressed: () {
setState(() {
(_recordState == RecordState.pause) ? _resume() : _pause();
});
},
return Container(
width: 60.0,
height: 60.0,
child: IconButton(
// isSelected: playProgressIndicator,
selectedIcon: const Icon(Icons.pause, size: 80.0),
icon: (_recordState == RecordState.record)? const Icon(Icons.pause, size: 40.0, color: Color(0x806750a4)): const Icon(Icons.play_arrow, size: 40.0, color: Color(0x806750a4)),
onPressed: () {
setState(() {
(_recordState == RecordState.pause) ? _resume() : _pause();
});
},
)
);
}

Widget _buildText() {
if (_recordState != RecordState.stop) {
return _buildTimer();
}
Widget _buildText(String text) {
debugPrint(text);
// if (_recordState != RecordState.stop) {
// return _buildTimer();
// }

return const Text("Waiting to record");
return Text(text,style: TextStyle(fontWeight: FontWeight.bold,fontSize: 18));
}

Widget _buildTimer() {
Expand Down
Loading