add bug report section to news

This commit is contained in:
Amir Hossein Mousavi 2023-09-18 08:04:40 +03:30
parent 5bd556e691
commit bb7f683389
7 changed files with 177 additions and 51 deletions

View File

@ -1,6 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'news_attachment.dart';
import 'radar_attachment.dart'; import 'radar_attachment.dart';
class MessageData { class MessageData {
@ -10,6 +11,7 @@ class MessageData {
final bool writedByAdmin; final bool writedByAdmin;
final bool readed; final bool readed;
final String createdAt; final String createdAt;
final NewsAttachment? news;
final RadarAttachment? radar; final RadarAttachment? radar;
final File? audioFile; final File? audioFile;
final int? audioDuration; final int? audioDuration;
@ -21,6 +23,7 @@ class MessageData {
required this.createdAt, required this.createdAt,
this.text, this.text,
this.audio, this.audio,
this.news,
this.radar, this.radar,
this.audioFile, this.audioFile,
this.audioDuration, this.audioDuration,
@ -39,6 +42,8 @@ class MessageData {
radar: json['radar'] == null radar: json['radar'] == null
? null ? null
: RadarAttachment.fromJson(json['radar']), : RadarAttachment.fromJson(json['radar']),
news:
json['news'] == null ? null : NewsAttachment.fromJson(json['news']),
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
@ -48,6 +53,7 @@ class MessageData {
'writedByAdmin': writedByAdmin, 'writedByAdmin': writedByAdmin,
'readed': readed, 'readed': readed,
'createdAt': createdAt, 'createdAt': createdAt,
'news': news?.toJson(),
'radar': radar?.toJson(), 'radar': radar?.toJson(),
}; };
} }

View File

@ -0,0 +1,30 @@
class NewsAttachment {
final int id;
final String title;
final String description;
final String image;
final String createdAt;
const NewsAttachment({
required this.id,
required this.title,
required this.description,
required this.image,
required this.createdAt,
});
factory NewsAttachment.fromJson(Map<String, dynamic> json) => NewsAttachment(
id: json['id'],
title: json['title'],
description: json['description'],
image: json['image'],
createdAt: json['createdAt'],
);
Map<String, dynamic> toJson() => {
'id': id,
'title': title,
'description': description,
'image': image,
};
}

View File

@ -28,6 +28,7 @@ class _DirectState extends State<Direct> {
@override @override
void initState() { void initState() {
final state = context.read<DirectState>(); final state = context.read<DirectState>();
state.replyNews = widget.pageData['newsAttachment'];
state.replyRadar = widget.pageData['radarAttachment']; state.replyRadar = widget.pageData['radarAttachment'];
final typeId = ServerDataProvider.labelToTypeId(widget.pageData['type']); final typeId = ServerDataProvider.labelToTypeId(widget.pageData['type']);
state.typeId = typeId; state.typeId = typeId;
@ -68,7 +69,8 @@ class _DirectState extends State<Direct> {
slivers: [ slivers: [
if (state.appState != AppState.busy) if (state.appState != AppState.busy)
SliverPadding( SliverPadding(
padding: state.replyRadar == null padding:
state.replyRadar == null && state.replyNews == null
? EdgeInsets.zero ? EdgeInsets.zero
: const EdgeInsets.only(bottom: 68), : const EdgeInsets.only(bottom: 68),
sliver: SliverStateHandler<DirectState>( sliver: SliverStateHandler<DirectState>(

View File

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:didvan/models/enums.dart'; import 'package:didvan/models/enums.dart';
import 'package:didvan/models/message_data/message_data.dart'; import 'package:didvan/models/message_data/message_data.dart';
import 'package:didvan/models/message_data/news_attachment.dart';
import 'package:didvan/models/message_data/radar_attachment.dart'; import 'package:didvan/models/message_data/radar_attachment.dart';
import 'package:didvan/providers/core.dart'; import 'package:didvan/providers/core.dart';
import 'package:didvan/services/media/media.dart'; import 'package:didvan/services/media/media.dart';
@ -19,6 +20,7 @@ class DirectState extends CoreProvier {
final List<int> deletionQueue = []; final List<int> deletionQueue = [];
String? text; String? text;
NewsAttachment? replyNews;
RadarAttachment? replyRadar; RadarAttachment? replyRadar;
File? recordedFile; File? recordedFile;
int? audioDuration; int? audioDuration;
@ -116,21 +118,30 @@ class DirectState extends CoreProvier {
audio: null, audio: null,
audioFile: recordedFile, audioFile: recordedFile,
radar: replyRadar, radar: replyRadar,
news: replyNews,
audioDuration: audioDuration, audioDuration: audioDuration,
), ),
); );
_addToDailyGrouped(messages.first); _addToDailyGrouped(messages.first);
final body = {}; final body = {};
if (text != null) { if (text != null) {
body.addAll({'text': text}); body.addAll({'text': text});
} }
if (replyRadar != null) { if (replyRadar != null) {
body.addAll({'radarId': replyRadar!.id}); body.addAll({'radarId': replyRadar!.id});
} }
if (replyNews != null) {
body.addAll({'newsId': replyNews!.id});
}
final uploadFile = recordedFile; final uploadFile = recordedFile;
text = null; text = null;
recordedFile = null; recordedFile = null;
replyRadar = null; replyRadar = null;
replyNews = null;
notifyListeners(); notifyListeners();
final service = final service =
RequestService(RequestHelper.sendDirectMessage(typeId), body: body); RequestService(RequestHelper.sendDirectMessage(typeId), body: body);

View File

@ -89,11 +89,16 @@ class Message extends StatelessWidget {
audioUrl: message.audio, audioUrl: message.audio,
id: message.id, id: message.id,
), ),
if (message.radar != null) const DidvanDivider(), if (message.radar != null || message.news != null)
if (message.radar != null) const SizedBox(height: 4), const DidvanDivider(),
if (message.radar != null || message.news != null)
const SizedBox(height: 4),
if (message.radar != null) if (message.radar != null)
_ReplyRadarOverview(message: message), _ReplyRadarOverview(message: message),
if (message.radar != null) const SizedBox(height: 4), if (message.news != null)
_ReplyNewsOverview(message: message),
if (message.radar != null || message.news != null)
const SizedBox(height: 4),
], ],
), ),
), ),
@ -168,7 +173,59 @@ class _ReplyRadarOverview extends StatelessWidget {
color: Theme.of(context).colorScheme.focusedBorder, color: Theme.of(context).colorScheme.focusedBorder,
style: Theme.of(context).textTheme.labelSmall, style: Theme.of(context).textTheme.labelSmall,
), ),
// DidvanText('text'), ],
),
],
),
),
),
],
);
}
}
class _ReplyNewsOverview extends StatelessWidget {
final MessageData message;
const _ReplyNewsOverview({Key? key, required this.message}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SkeletonImage(
imageUrl: message.news!.image,
height: 52,
width: 52,
),
const SizedBox(width: 8),
Expanded(
child: SizedBox(
height: 52,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
DidvanText(
message.news!.title,
style: Theme.of(context).textTheme.bodyLarge,
maxLines: 1,
overflow: TextOverflow.ellipsis,
color: Theme.of(context).colorScheme.focusedBorder,
),
Row(
children: [
DidvanText(
'خبر',
style: Theme.of(context).textTheme.labelSmall,
color: Theme.of(context).colorScheme.focusedBorder,
),
const Spacer(),
DidvanText(
DateTimeUtils.momentGenerator(message.news!.createdAt),
color: Theme.of(context).colorScheme.focusedBorder,
style: Theme.of(context).textTheme.labelSmall,
),
], ],
), ),
], ],

View File

@ -17,7 +17,8 @@ class MessageBox extends StatelessWidget {
return Column( return Column(
children: [ children: [
Consumer<DirectState>( Consumer<DirectState>(
builder: (context, state, child) => state.replyRadar != null builder: (context, state, child) => state.replyRadar != null ||
state.replyNews != null
? _MessageBoxContainer( ? _MessageBoxContainer(
isMessage: false, isMessage: false,
child: Padding( child: Padding(
@ -32,7 +33,9 @@ class MessageBox extends StatelessWidget {
'لینک به مطلب:', 'لینک به مطلب:',
), ),
DidvanText( DidvanText(
state.replyRadar!.title, state.replyRadar != null
? state.replyRadar!.title
: state.replyNews!.title,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 1, maxLines: 1,
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
@ -45,6 +48,7 @@ class MessageBox extends StatelessWidget {
gestureSize: 24, gestureSize: 24,
onPressed: () { onPressed: () {
state.replyRadar = null; state.replyRadar = null;
state.replyNews = null;
state.update(); state.update();
}, },
), ),

View File

@ -1,6 +1,7 @@
import 'package:didvan/config/design_config.dart'; import 'package:didvan/config/design_config.dart';
import 'package:didvan/config/theme_data.dart'; import 'package:didvan/config/theme_data.dart';
import 'package:didvan/constants/app_icons.dart'; import 'package:didvan/constants/app_icons.dart';
import 'package:didvan/models/message_data/news_attachment.dart';
import 'package:didvan/models/message_data/radar_attachment.dart'; import 'package:didvan/models/message_data/radar_attachment.dart';
import 'package:didvan/models/view/action_sheet_data.dart'; import 'package:didvan/models/view/action_sheet_data.dart';
import 'package:didvan/routes/routes.dart'; import 'package:didvan/routes/routes.dart';
@ -102,10 +103,9 @@ class _FloatingNavigationBarState extends State<FloatingNavigationBar> {
), ),
), ),
const Spacer(), const Spacer(),
if (widget.isRadar)
BookmarkButton( BookmarkButton(
itemId: widget.item.id, itemId: widget.item.id,
type: 'radar', type: widget.isRadar ? 'radar' : 'news',
color: DesignConfig.isDark color: DesignConfig.isDark
? Theme.of(context).colorScheme.focusedBorder ? Theme.of(context).colorScheme.focusedBorder
: Theme.of(context).colorScheme.focused, : Theme.of(context).colorScheme.focused,
@ -145,28 +145,10 @@ class _FloatingNavigationBarState extends State<FloatingNavigationBar> {
], ],
), ),
), ),
if (!widget.isRadar) const SizedBox(width: 12),
if (!widget.isRadar)
BookmarkButton(
itemId: widget.item.id,
type: 'news',
color: DesignConfig.isDark
? Theme.of(context).colorScheme.focusedBorder
: Theme.of(context).colorScheme.focused,
askForConfirmation: widget.hasUnmarkConfirmation,
value: widget.item.marked,
onMarkChanged: (value) {
widget.onMarkChanged(value);
if (widget.hasUnmarkConfirmation && !value) {
Navigator.of(context).pop();
}
},
gestureSize: 32,
),
if (widget.isRadar)
DidvanIconButton( DidvanIconButton(
gestureSize: 32, gestureSize: 32,
onPressed: _showMoreOptions, onPressed:
widget.isRadar ? _showRadarMoreOptions : _showNewsMoreOptions,
icon: DidvanIcons.menu_regular, icon: DidvanIcons.menu_regular,
), ),
], ],
@ -192,7 +174,7 @@ class _FloatingNavigationBarState extends State<FloatingNavigationBar> {
}); });
} }
void _showMoreOptions() { void _showRadarMoreOptions() {
final categories = widget.item.categories!; final categories = widget.item.categories!;
ActionSheetUtils.showBottomSheet( ActionSheetUtils.showBottomSheet(
data: ActionSheetData( data: ActionSheetData(
@ -293,4 +275,38 @@ class _FloatingNavigationBarState extends State<FloatingNavigationBar> {
), ),
); );
} }
void _showNewsMoreOptions() {
ActionSheetUtils.showBottomSheet(
data: ActionSheetData(
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MenuOption(
title: 'گزارش اشکال',
onTap: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed(
Routes.direct,
arguments: {
'newsAttachment': NewsAttachment(
id: widget.item.id,
title: widget.item.title,
description: widget.item.contents.first.text,
image: widget.item.image,
createdAt: widget.item.createdAt,
),
'type': 'پشتیبانی'
},
);
},
icon: DidvanIcons.description_regular,
),
],
),
title: 'موارد بیشتر',
withoutButtonMode: true,
),
);
}
} }