155 lines
5.8 KiB
Dart
155 lines
5.8 KiB
Dart
import 'package:didvan/constants/app_icons.dart';
|
|
import 'package:didvan/constants/assets.dart';
|
|
import 'package:didvan/models/enums.dart';
|
|
import 'package:didvan/models/view/app_bar_data.dart';
|
|
import 'package:didvan/providers/server_data.dart';
|
|
import 'package:didvan/services/media/media.dart';
|
|
import 'package:didvan/views/home/direct/direct_state.dart';
|
|
import 'package:didvan/views/home/direct/widgets/message.dart';
|
|
import 'package:didvan/views/home/direct/widgets/message_box.dart';
|
|
import 'package:didvan/views/widgets/didvan/icon_button.dart';
|
|
import 'package:didvan/views/widgets/didvan/scaffold.dart';
|
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
|
import 'package:didvan/views/widgets/state_handlers/empty_state.dart';
|
|
import 'package:didvan/views/widgets/state_handlers/sliver_state_handler.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class Direct extends StatefulWidget {
|
|
final Map<String, dynamic> pageData;
|
|
const Direct({Key? key, required this.pageData}) : super(key: key);
|
|
|
|
@override
|
|
State<Direct> createState() => _DirectState();
|
|
}
|
|
|
|
class _DirectState extends State<Direct> {
|
|
@override
|
|
void initState() {
|
|
final state = context.read<DirectState>();
|
|
state.replyRadar = widget.pageData['radarAttachment'];
|
|
final typeId = ServerDataProvider.labelToTypeId(widget.pageData['type']);
|
|
state.typeId = typeId;
|
|
Future.delayed(Duration.zero, () {
|
|
state.getMessages();
|
|
});
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final state = context.watch<DirectState>();
|
|
final d = MediaQuery.of(context);
|
|
return WillPopScope(
|
|
onWillPop: () async {
|
|
MediaService.resetAudioPlayer();
|
|
return true;
|
|
},
|
|
child: Material(
|
|
child: Stack(
|
|
children: [
|
|
Positioned(
|
|
top: 0,
|
|
bottom: 56,
|
|
left: 0,
|
|
right: 0,
|
|
child: DidvanScaffold(
|
|
padding: EdgeInsets.zero,
|
|
reverse: true,
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
|
appBarData: AppBarData(
|
|
hasBack: true,
|
|
subtitle: widget.pageData['type'].contains('پشتیبانی')
|
|
? null
|
|
: 'ارتباط با سردبیر',
|
|
title: widget.pageData['type'] ?? 'پشتیبانی اپلیکیشن',
|
|
),
|
|
slivers: [
|
|
if (state.appState != AppState.busy)
|
|
SliverPadding(
|
|
padding: state.replyRadar == null
|
|
? EdgeInsets.zero
|
|
: const EdgeInsets.only(bottom: 68),
|
|
sliver: SliverStateHandler<DirectState>(
|
|
itemPadding: const EdgeInsets.only(bottom: 12),
|
|
state: state,
|
|
enableEmptyState: state.messages.isEmpty,
|
|
emptyState: Padding(
|
|
padding: const EdgeInsets.only(bottom: 160),
|
|
child: EmptyState(
|
|
asset: Assets.emptyChat,
|
|
title: 'اولین پیام را بنویسید...',
|
|
),
|
|
),
|
|
builder: (context, state, index) => Message(
|
|
message: state.messages[index],
|
|
),
|
|
childCount: state.messages.length,
|
|
onRetry: state.getMessages,
|
|
),
|
|
),
|
|
],
|
|
children: [
|
|
if (state.appState == AppState.busy)
|
|
SizedBox(
|
|
height: d.size.height - kToolbarHeight - d.padding.top,
|
|
child: Center(
|
|
child: SpinKitSpinningLines(
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Positioned(
|
|
bottom: d.viewInsets.bottom,
|
|
right: 0,
|
|
left: 0,
|
|
child: const MessageBox(),
|
|
),
|
|
if (state.deletionQueue.isNotEmpty)
|
|
Positioned(
|
|
left: 0,
|
|
right: 0,
|
|
top: d.padding.top,
|
|
child: Container(
|
|
height: 72,
|
|
color: Theme.of(context).colorScheme.surface,
|
|
child: Row(
|
|
children: [
|
|
DidvanIconButton(
|
|
icon: DidvanIcons.close_solid,
|
|
size: 32,
|
|
gestureSize: 48,
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
onPressed: () {
|
|
state.deletionQueue.clear();
|
|
state.update();
|
|
},
|
|
),
|
|
DidvanText(
|
|
'${state.deletionQueue.length} مورد انتخاب شد',
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
),
|
|
const Spacer(),
|
|
DidvanIconButton(
|
|
icon: DidvanIcons.trash_solid,
|
|
size: 32,
|
|
gestureSize: 48,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
onPressed: state.delete,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|