132 lines
3.7 KiB
Dart
132 lines
3.7 KiB
Dart
import 'package:didvan/config/theme_data.dart';
|
|
import 'package:didvan/constants/app_icons.dart';
|
|
import 'package:didvan/pages/home/direct/direct_state.dart';
|
|
import 'package:didvan/widgets/audio_visualizer.dart';
|
|
import 'package:didvan/widgets/didvan/icon_button.dart';
|
|
import 'package:didvan/widgets/didvan/text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class MessageBox extends StatelessWidget {
|
|
const MessageBox({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
height: 56,
|
|
decoration: BoxDecoration(
|
|
border: Border(
|
|
top: BorderSide(
|
|
color: Theme.of(context).colorScheme.cardBorder,
|
|
),
|
|
),
|
|
color: Theme.of(context).colorScheme.surface,
|
|
),
|
|
child: Consumer<DirectState>(
|
|
builder: (context, state, child) {
|
|
if (state.isRecording) {
|
|
return const _Recording();
|
|
} else if (!state.isRecording && state.recordedFile != null) {
|
|
return const _RecordChecking();
|
|
}
|
|
return const _Typing();
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Typing extends StatelessWidget {
|
|
const _Typing({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final state = context.read<DirectState>();
|
|
return Row(
|
|
children: [
|
|
DidvanIconButton(
|
|
icon: DidvanIcons.mic_solid,
|
|
onPressed: state.startRecording,
|
|
size: 32,
|
|
color: Theme.of(context).colorScheme.focusedBorder,
|
|
),
|
|
Expanded(
|
|
child: TextField(
|
|
textInputAction: TextInputAction.send,
|
|
decoration: InputDecoration(
|
|
border: InputBorder.none,
|
|
hintText: 'بنویسید یا پیام صوتی بگذارید...',
|
|
hintStyle: Theme.of(context)
|
|
.textTheme
|
|
.caption!
|
|
.copyWith(color: Theme.of(context).colorScheme.disabledText),
|
|
),
|
|
onChanged: (value) {},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Recording extends StatelessWidget {
|
|
const _Recording({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final state = context.read<DirectState>();
|
|
return Row(
|
|
children: [
|
|
DidvanIconButton(
|
|
icon: DidvanIcons.send_solid,
|
|
onPressed: () => state.stopRecording(true),
|
|
gestureSize: 52,
|
|
),
|
|
Expanded(
|
|
child: DidvanText(
|
|
'در حال ضبط صدا ...',
|
|
style: Theme.of(context).textTheme.caption,
|
|
),
|
|
),
|
|
DidvanIconButton(
|
|
icon: DidvanIcons.stop_circle_solid,
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
onPressed: () => state.stopRecording(false),
|
|
size: 32,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _RecordChecking extends StatelessWidget {
|
|
const _RecordChecking({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final state = context.read<DirectState>();
|
|
return Row(
|
|
children: [
|
|
DidvanIconButton(
|
|
icon: DidvanIcons.send_solid,
|
|
onPressed: () => state.stopRecording(true),
|
|
color: Theme.of(context).colorScheme.focusedBorder,
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
child: AudioVisualizer(
|
|
audioFile: state.recordedFile!,
|
|
),
|
|
),
|
|
),
|
|
DidvanIconButton(
|
|
icon: DidvanIcons.trash_solid,
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
onPressed: state.deleteRecordedFile,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|