@@ -50,6 +50,7 @@ import 'package:dan_xi/widget/forum/forum_widgets.dart';
50
50
import 'package:flutter/cupertino.dart' ;
51
51
import 'package:flutter/material.dart' ;
52
52
import 'package:flutter/services.dart' ;
53
+ import 'package:flutter/widgets.dart' ;
53
54
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart' ;
54
55
import 'package:flutter_progress_dialog/flutter_progress_dialog.dart' ;
55
56
import 'package:intl/intl.dart' ;
@@ -127,8 +128,7 @@ class BBSPostDetailState extends State<BBSPostDetail> {
127
128
Future <List <OTFloor >?> _loadContent (int page) async {
128
129
Future <List <OTFloor >?> loadPunishmentHistory (int page) async {
129
130
if (page == 0 ) {
130
- return (await ForumRepository .getInstance ()
131
- .getPunishmentHistory ())
131
+ return (await ForumRepository .getInstance ().getPunishmentHistory ())
132
132
? .map ((e) => e.floor! )
133
133
.toList ();
134
134
} else {
@@ -140,10 +140,9 @@ class BBSPostDetailState extends State<BBSPostDetail> {
140
140
final results = switch (_renderModel) {
141
141
Normal (hole: var hole) => await ForumRepository .getInstance ()
142
142
.loadFloors (hole, startFloor: page * Constant .POST_COUNT_PER_PAGE ),
143
- Search (keyword: var searchKeyword) =>
144
- await ForumRepository .getInstance ().loadSearchResults (
145
- searchKeyword,
146
- startFloor: _listViewController.length ()),
143
+ Search (keyword: var searchKeyword) => await ForumRepository .getInstance ()
144
+ .loadSearchResults (searchKeyword,
145
+ startFloor: _listViewController.length ()),
147
146
PunishmentHistory () => await loadPunishmentHistory (page),
148
147
};
149
148
@@ -183,8 +182,8 @@ class BBSPostDetailState extends State<BBSPostDetail> {
183
182
184
183
// Update hole view count
185
184
if (hole.hole_id != null ) {
186
- unawaited (ForumRepository . getInstance ()
187
- .updateHoleViewCount (hole.hole_id! ));
185
+ unawaited (
186
+ ForumRepository . getInstance () .updateHoleViewCount (hole.hole_id! ));
188
187
}
189
188
} else if (widget.arguments! .containsKey ('searchKeyword' )) {
190
189
_renderModel = Search (widget.arguments! ['searchKeyword' ]);
@@ -685,9 +684,7 @@ class BBSPostDetailState extends State<BBSPostDetail> {
685
684
Navigator .of (cxt).pop (newDivision);
686
685
}
687
686
688
- ForumRepository .getInstance ()
689
- .getDivisions ()
690
- .forEach ((value) {
687
+ ForumRepository .getInstance ().getDivisions ().forEach ((value) {
691
688
list.add (ListTile (
692
689
title: Text (value.name ?? "null" ),
693
690
subtitle: Text (value.description ?? "" ),
@@ -777,16 +774,16 @@ class BBSPostDetailState extends State<BBSPostDetail> {
777
774
String postTimeStr = S .of (menuContext).post_time (postTime);
778
775
779
776
List <Widget > menu = [
780
- if (e.is_me == true && e.deleted == false )
777
+ if (e.is_me == true && e.deleted == false ) ...[
781
778
PlatformContextMenuItem (
782
779
menuContext: menuContext,
783
780
onPressed: () async {
784
781
if (await OTEditor .modifyReply (
785
782
context, e.hole_id, e.floor_id, e.content)) {
783
+ if (! context.mounted) return ;
786
784
Noticing .showMaterialNotice (
787
785
context, S .of (context).request_success);
788
- ForumRepository .getInstance ()
789
- .invalidateFloorCache (e.floor_id! );
786
+ ForumRepository .getInstance ().invalidateFloorCache (e.floor_id! );
790
787
final newFloor = await ForumRepository .getInstance ()
791
788
.loadSpecificFloor (e.floor_id! );
792
789
_listViewController.replaceDatumWith (e, newFloor! );
@@ -798,6 +795,31 @@ class BBSPostDetailState extends State<BBSPostDetail> {
798
795
},
799
796
child: Text (S .of (context).modify),
800
797
),
798
+ PlatformContextMenuItem (
799
+ menuContext: menuContext,
800
+ onPressed: () async {
801
+ if (await Noticing .showConfirmationDialog (context,
802
+ S .of (context).about_to_delete_floor (e.floor_id ?? "null" ),
803
+ title: S .of (context).are_you_sure,
804
+ isConfirmDestructive: true ) ==
805
+ true ) {
806
+ if (! context.mounted) return ;
807
+ try {
808
+ await ForumRepository .getInstance ().deleteFloor (e.floor_id! );
809
+ Noticing .showMaterialNotice (
810
+ context, S .of (context).request_success);
811
+ ForumRepository .getInstance ().invalidateFloorCache (e.floor_id! );
812
+ final newFloor = await ForumRepository .getInstance ()
813
+ .loadSpecificFloor (e.floor_id! );
814
+ _listViewController.replaceDatumWith (e, newFloor! );
815
+ } catch (e, st) {
816
+ Noticing .showErrorDialog (context, e, trace: st);
817
+ }
818
+ }
819
+ },
820
+ child: Text (S .of (context).delete),
821
+ )
822
+ ],
801
823
802
824
// Standard Operations
803
825
PlatformContextMenuItem (
@@ -854,6 +876,7 @@ class BBSPostDetailState extends State<BBSPostDetail> {
854
876
isDestructive: true ,
855
877
onPressed: () async {
856
878
if (await OTEditor .reportPost (context, e.floor_id)) {
879
+ if (! context.mounted) return ;
857
880
Noticing .showMaterialNotice (context, S .of (context).report_success);
858
881
}
859
882
},
@@ -993,8 +1016,7 @@ class BBSPostDetailState extends State<BBSPostDetail> {
993
1016
.loadFloors (hole,
994
1017
startFloor: pageIndex * Constant .POST_COUNT_PER_PAGE ),
995
1018
Search (keyword: var searchKeyword) =>
996
- await ForumRepository .getInstance ().loadSearchResults (
997
- searchKeyword,
1019
+ await ForumRepository .getInstance ().loadSearchResults (searchKeyword,
998
1020
startFloor: pageIndex * Constant .POST_COUNT_PER_PAGE ),
999
1021
PunishmentHistory () =>
1000
1022
(await ForumRepository .getInstance ().getPunishmentHistory ())
@@ -1017,14 +1039,6 @@ class BBSPostDetailState extends State<BBSPostDetail> {
1017
1039
final floorWidget = OTFloorWidget (
1018
1040
hasBackgroundImage: _backgroundImage != null ,
1019
1041
floor: floor,
1020
- // Refresh single floor when modified or deleted
1021
- onOperation: () async {
1022
- ForumRepository .getInstance ()
1023
- .invalidateFloorCache (floor.floor_id! );
1024
- final newFloor = await ForumRepository .getInstance ()
1025
- .loadSpecificFloor (floor.floor_id! );
1026
- _listViewController.replaceDatumWith (floor, newFloor! );
1027
- },
1028
1042
index: _renderModel is Normal ? index : null ,
1029
1043
isInMention: isNested,
1030
1044
parentHole: switch (_renderModel) {
@@ -1077,8 +1091,8 @@ class BBSPostDetailState extends State<BBSPostDetail> {
1077
1091
final int length = _listViewController.length ();
1078
1092
smartNavigatorPush (context, '/image/detail' , arguments: {
1079
1093
'preview_url' : url,
1080
- 'hd_url' : ForumRepository . getInstance ()
1081
- .extractHighDefinitionImageUrl (url! ),
1094
+ 'hd_url' :
1095
+ ForumRepository . getInstance () .extractHighDefinitionImageUrl (url! ),
1082
1096
'hero_tag' : heroTag,
1083
1097
'image_list' : extractAllImages (),
1084
1098
'loader' : loadPageImage,
0 commit comments