Skip to content

Commit a6d54c4

Browse files
Fix several bugs
1 parent ce10a78 commit a6d54c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+642
-652
lines changed

lib/Models/nav_entry.dart

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -59,122 +59,3 @@ class SortableItem {
5959
);
6060
}
6161
}
62-
63-
class SortableItemList {
64-
static List<SortableItem> defaultNavItems = <SortableItem>[
65-
SortableItem(
66-
id: "home",
67-
index: 1,
68-
lightIcon: AssetUtil.homeLightIcon,
69-
lightSelectedIcon: AssetUtil.homeLightSelectedIcon,
70-
darkIcon: AssetUtil.homeDarkIcon,
71-
darkSelectedIcon: AssetUtil.homeDarkSelectedIcon,
72-
hidden: false,
73-
canBeHidden: false,
74-
),
75-
SortableItem(
76-
id: "dynamic",
77-
lightIcon: AssetUtil.dynamicLightIcon,
78-
lightSelectedIcon: AssetUtil.dynamicLightSelectedIcon,
79-
darkIcon: AssetUtil.dynamicDarkIcon,
80-
darkSelectedIcon: AssetUtil.dynamicDarkSelectedIcon,
81-
index: 2,
82-
hidden: false,
83-
canBeHidden: false,
84-
),
85-
SortableItem(
86-
id: "mine",
87-
index: 4,
88-
lightIcon: AssetUtil.mineLightIcon,
89-
lightSelectedIcon: AssetUtil.mineLightSelectedIcon,
90-
darkIcon: AssetUtil.mineDarkIcon,
91-
darkSelectedIcon: AssetUtil.mineDarkSelectedIcon,
92-
hidden: false,
93-
canBeHidden: false,
94-
),
95-
];
96-
97-
static Map<String, GlobalKey> navItemKeyMap = {
98-
"home": GlobalKey(),
99-
'dynamic': GlobalKey(),
100-
'mine': GlobalKey(),
101-
};
102-
103-
static Map<String, Widget> navItemPageMap = {
104-
"home": HomeScreen(key: navItemKeyMap['home']),
105-
'mine': MineScreen(key: navItemKeyMap['mine']),
106-
'dynamic': DynamicScreen(key: navItemKeyMap['dynamic']),
107-
};
108-
109-
static Widget getNavItemPage(String id) {
110-
return navItemPageMap[id]!;
111-
}
112-
113-
static GlobalKey getNavItemKey(String id) {
114-
return navItemKeyMap[id]!;
115-
}
116-
117-
static String getNavItemLabel(String id) {
118-
Map<String, String> idToLabelMap = {
119-
"home": S.current.home,
120-
'dynamic': S.current.dynamic,
121-
"mine": S.current.mine,
122-
};
123-
return idToLabelMap[id] ?? "";
124-
}
125-
126-
List<SortableItem> items;
127-
List<SortableItem> defaultItems;
128-
129-
SortableItemList({
130-
required this.items,
131-
required this.defaultItems,
132-
});
133-
134-
static int compare(SortableItem a, SortableItem b) {
135-
return a.index - b.index;
136-
}
137-
138-
List<SortableItem> getList() {
139-
items.sort(compare);
140-
return items;
141-
}
142-
143-
List<SortableItem> mergeMeta(List<SortableItem> list) {
144-
for (SortableItem updateItem in defaultItems) {
145-
for (SortableItem item in list) {
146-
if (updateItem.id == item.id) {
147-
item.canBeHidden = updateItem.canBeHidden;
148-
item.lightIcon = updateItem.lightIcon;
149-
item.lightSelectedIcon = updateItem.lightSelectedIcon;
150-
item.darkIcon = updateItem.darkIcon;
151-
item.darkSelectedIcon = updateItem.darkSelectedIcon;
152-
break;
153-
}
154-
}
155-
}
156-
return list;
157-
}
158-
159-
List<SortableItem> getHiddenItems() {
160-
items.sort(compare);
161-
List<SortableItem> hiddenItems = [];
162-
for (SortableItem entry in items) {
163-
if (entry.canBeHidden && entry.hidden) hiddenItems.add(entry);
164-
}
165-
return mergeMeta(hiddenItems);
166-
}
167-
168-
List<SortableItem> getShownItems() {
169-
items.sort(compare);
170-
List<SortableItem> showItems = [];
171-
List<String> ids = List.generate(items.length, (index) => items[index].id);
172-
for (SortableItem entry in items) {
173-
if (!(entry.canBeHidden && entry.hidden)) showItems.add(entry);
174-
}
175-
for (SortableItem updateItem in defaultItems) {
176-
if (!ids.contains(updateItem.id)) showItems.add(updateItem);
177-
}
178-
return mergeMeta(showItems);
179-
}
180-
}

lib/Models/recommend_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ class VideoInfo {
957957
imgWidth: json['imgWidth'] ?? json['img_width'] ?? "",
958958
originUrl: json['originUrl'] ?? "",
959959
size: Utils.parseToInt(json['size']),
960-
type: Utils.parseToInt(json['type']).toString(),
960+
type: json['type'],
961961
vid: Utils.parseToInt(json['vid']),
962962
videoFirstImg: json['videoFirstImg'] ?? json['video_first_img'] ?? "",
963963
videoImgUrl: json['videoImgUrl'] ?? json['video_img_url'] ?? "",

lib/Resources/theme.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ class MyTheme {
2828
);
2929
}
3030

31-
static BoxDecoration getDefaultDecoration([double radius = 10,double borderWidth=1]) {
31+
static BoxDecoration getDefaultDecoration(
32+
[double radius = 10, double borderWidth = 1]) {
3233
return BoxDecoration(
3334
color: Theme.of(rootContext).canvasColor,
34-
border: Border.all(color: Theme.of(rootContext).dividerColor, width: borderWidth),
35+
border: Border.all(
36+
color: Theme.of(rootContext).dividerColor, width: borderWidth),
3537
boxShadow: defaultBoxShadow,
3638
borderRadius: BorderRadius.circular(radius),
3739
);

lib/Screens/Info/collection_screen.dart

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class _CollectionScreenState extends State<CollectionScreen>
5151
bool _loading = false;
5252
final EasyRefreshController _refreshController = EasyRefreshController();
5353
bool _noMore = false;
54+
InitPhase _initPhase = InitPhase.haveNotConnected;
5455

5556
@override
5657
void initState() {
@@ -61,16 +62,18 @@ class _CollectionScreenState extends State<CollectionScreen>
6162
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
6263
}
6364
super.initState();
64-
if (widget.infoMode != InfoMode.me) {
65-
_onRefresh();
66-
}
65+
_onRefresh();
6766
}
6867

6968
_fetchGrain({bool refresh = false}) async {
7069
if (_loading) return;
7170
if (refresh) _noMore = false;
7271
_loading = true;
7372
int offset = refresh ? 0 : _collectionList.length;
73+
if (_initPhase != InitPhase.successful) {
74+
_initPhase = InitPhase.connecting;
75+
setState(() {});
76+
}
7477
return await HiveUtil.getUserInfo().then((blogInfo) async {
7578
String blogName = widget.infoMode == InfoMode.me
7679
? blogInfo!.blogName
@@ -94,6 +97,7 @@ class _CollectionScreenState extends State<CollectionScreen>
9497
}
9598
_collectionList.addAll(tmp);
9699
if (mounted) setState(() {});
100+
_initPhase = InitPhase.successful;
97101
if (((widget.collectionCount != null &&
98102
_collectionList.length >= widget.collectionCount!) ||
99103
tmp.isEmpty) &&
@@ -105,6 +109,7 @@ class _CollectionScreenState extends State<CollectionScreen>
105109
}
106110
}
107111
} catch (e, t) {
112+
_initPhase = InitPhase.failed;
108113
ILogger.error("Failed to load collection list", e, t);
109114
if (mounted) IToast.showTop("加载失败");
110115
return IndicatorResult.fail;
@@ -132,20 +137,40 @@ class _CollectionScreenState extends State<CollectionScreen>
132137
? MyTheme.getBackground(context)
133138
: Colors.transparent,
134139
appBar: widget.infoMode == InfoMode.me ? _buildAppBar() : null,
135-
body: EasyRefresh.builder(
136-
refreshOnStart: true,
137-
controller: _refreshController,
138-
onRefresh: _onRefresh,
139-
onLoad: _onLoad,
140-
triggerAxis: Axis.vertical,
141-
childBuilder: (context, physics) {
142-
return _buildBody(physics);
143-
},
144-
),
140+
body: _buildBody(),
145141
);
146142
}
147143

148-
Widget _buildBody(ScrollPhysics physics) {
144+
_buildBody() {
145+
switch (_initPhase) {
146+
case InitPhase.connecting:
147+
return ItemBuilder.buildLoadingDialog(context,
148+
background: Colors.transparent);
149+
case InitPhase.failed:
150+
return ItemBuilder.buildError(
151+
context: context,
152+
onTap: _onRefresh,
153+
);
154+
case InitPhase.successful:
155+
return EasyRefresh.builder(
156+
refreshOnStart: true,
157+
controller: _refreshController,
158+
onRefresh: _onRefresh,
159+
onLoad: _onLoad,
160+
triggerAxis: Axis.vertical,
161+
childBuilder: (context, physics) {
162+
return _collectionList.isNotEmpty
163+
? _buildMainBody(physics)
164+
: ItemBuilder.buildEmptyPlaceholder(
165+
context: context, text: "暂无合集");
166+
},
167+
);
168+
default:
169+
return Container();
170+
}
171+
}
172+
173+
Widget _buildMainBody(ScrollPhysics physics) {
149174
return ItemBuilder.buildLoadMoreNotification(
150175
noMore: _noMore,
151176
onLoad: _onLoad,

lib/Screens/Info/dress_screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class _DressScreenState extends State<DressScreen>
221221
return ItemBuilder.buildDesktopAppBar(
222222
context: context,
223223
showBack: true,
224+
centerInMobile: Utils.isNotEmpty(widget.tag),
224225
titleWidget: Utils.isNotEmpty(widget.tag)
225226
? ItemBuilder.buildClickItem(
226227
ItemBuilder.buildTagItem(

lib/Screens/Info/grain_screen.dart

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class _GrainScreenState extends State<GrainScreen>
5151
int _offset = 0;
5252
final EasyRefreshController _refreshController = EasyRefreshController();
5353
bool _noMore = false;
54+
InitPhase _initPhase = InitPhase.haveNotConnected;
5455

5556
@override
5657
void initState() {
@@ -61,16 +62,18 @@ class _GrainScreenState extends State<GrainScreen>
6162
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
6263
}
6364
super.initState();
64-
if (widget.infoMode != InfoMode.me) {
65-
_onRefresh();
66-
}
65+
_onRefresh();
6766
}
6867

6968
_fetchGrain({bool refresh = false}) async {
7069
if (_loading) return;
7170
if (refresh) _noMore = false;
7271
_loading = true;
7372
int offset = refresh ? 0 : _grainList.length;
73+
if (_initPhase != InitPhase.successful) {
74+
_initPhase = InitPhase.connecting;
75+
setState(() {});
76+
}
7477
return await HiveUtil.getUserInfo().then((blogInfo) async {
7578
int blogId =
7679
widget.infoMode == InfoMode.me ? blogInfo!.blogId : widget.blogId!;
@@ -91,6 +94,7 @@ class _GrainScreenState extends State<GrainScreen>
9194
}
9295
}
9396
if (mounted) setState(() {});
97+
_initPhase = InitPhase.successful;
9498
if ((t.isEmpty || _grainList.length > _total) && !refresh) {
9599
_noMore = true;
96100
return IndicatorResult.noMore;
@@ -99,6 +103,7 @@ class _GrainScreenState extends State<GrainScreen>
99103
}
100104
}
101105
} catch (e, t) {
106+
_initPhase = InitPhase.failed;
102107
ILogger.error("Failed to load grain list", e, t);
103108
if (mounted) IToast.showTop("加载失败");
104109
return IndicatorResult.fail;
@@ -126,20 +131,40 @@ class _GrainScreenState extends State<GrainScreen>
126131
? MyTheme.getBackground(context)
127132
: Colors.transparent,
128133
appBar: widget.infoMode == InfoMode.me ? _buildAppBar() : null,
129-
body: EasyRefresh.builder(
130-
refreshOnStart: true,
131-
controller: _refreshController,
132-
onRefresh: _onRefresh,
133-
onLoad: _onLoad,
134-
triggerAxis: Axis.vertical,
135-
childBuilder: (context, physics) {
136-
return _buildBody(physics);
137-
},
138-
),
134+
body: _buildBody(),
139135
);
140136
}
141137

142-
Widget _buildBody(ScrollPhysics physics) {
138+
_buildBody() {
139+
switch (_initPhase) {
140+
case InitPhase.connecting:
141+
return ItemBuilder.buildLoadingDialog(context,
142+
background: Colors.transparent);
143+
case InitPhase.failed:
144+
return ItemBuilder.buildError(
145+
context: context,
146+
onTap: _onRefresh,
147+
);
148+
case InitPhase.successful:
149+
return EasyRefresh.builder(
150+
refreshOnStart: true,
151+
controller: _refreshController,
152+
onRefresh: _onRefresh,
153+
onLoad: _onLoad,
154+
triggerAxis: Axis.vertical,
155+
childBuilder: (context, physics) {
156+
return _grainList.isNotEmpty
157+
? _buildMainBody(physics)
158+
: ItemBuilder.buildEmptyPlaceholder(
159+
context: context, text: "暂无粮单");
160+
},
161+
);
162+
default:
163+
return Container();
164+
}
165+
}
166+
167+
Widget _buildMainBody(ScrollPhysics physics) {
143168
return ItemBuilder.buildLoadMoreNotification(
144169
noMore: _noMore,
145170
onLoad: _onLoad,

0 commit comments

Comments
 (0)