修了一些问题

main
落雨楓 2 years ago
parent a8e5d51a3a
commit 08fae6fd4c

@ -110,11 +110,16 @@ class BaseApi {
static Future<String> post(Uri uri, {Map<String, dynamic>? search, dynamic data}) async {
var client = await getClient();
String? contentType;
if (data is Map) {
contentType = Headers.formUrlEncodedContentType;
}
var res = await client.post<String>(
uri.toString(),
queryParameters: search,
data: data,
options: Options(responseType: ResponseType.plain),
options: Options(responseType: ResponseType.plain, contentType: contentType),
);
if (res.statusCode != null && res.statusCode != 200) {

@ -115,26 +115,25 @@ class MWApi {
static Future<MWResponse<Map<String, dynamic>>> post(String action,
{Map<String, dynamic>? params, String? withToken}) async {
Map<String, String> paramsStr =
params?.map((key, value) => MapEntry(key, value.toString())) ?? {};
paramsStr.addAll({
params ??= {};
params.addAll({
"action": action,
"format": "json",
"formatversion": "2",
"formatversion": 2,
"uselang": Global.wikiLang,
});
if (Global.webOrigin != null) {
paramsStr["origin"] = Global.webOrigin!;
params["origin"] = Global.webOrigin!;
}
var resText = "";
try {
if (withToken != null) {
// CSRF Token
paramsStr["token"] = await getToken(type: withToken);
params["token"] = await getToken(type: withToken);
}
resText = await BaseApi.post(apiBaseUri, data: paramsStr);
resText = await BaseApi.post(apiBaseUri, data: params);
} on DioError catch (err) {
if (err.type == DioErrorType.response) {
if (err.response != null) {

@ -1,6 +1,7 @@
// ignore_for_file: invalid_annotation_target
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:isekai_wiki/utils/utils.dart';
part 'page_info.freezed.dart';
part 'page_info.g.dart';
@ -20,6 +21,8 @@ class PageInfo {
String? pagelanguage;
String? pagelanguagehtmlcode;
String? pagelanguagedir;
@JsonKey(fromJson: _inwatchlistFromInt, toJson: _inwatchlistToInt)
bool? inwatchlist;
@JsonKey(name: "touched")
@ -62,6 +65,22 @@ class PageInfo {
factory PageInfo.fromJson(Map<String, dynamic> json) => _$PageInfoFromJson(json);
Map<String, dynamic> toJson() => _$PageInfoToJson(this);
static bool? _inwatchlistFromInt(int? val) {
if (val != null) {
return val == 1;
} else {
return null;
}
}
static int? _inwatchlistToInt(bool? val) {
if (val != null) {
return val ? 1 : 0;
} else {
return null;
}
}
}
@freezed

@ -18,7 +18,7 @@ typedef AddFavoriteCallback = Future<bool> Function(
typedef PageInfoCallback = Future<void> Function(PageInfo pageInfo);
class PageCardStyles {
static const double cardInnerHeight = 140;
static const double cardInnerHeight = 150;
static const cardInnerPadding = EdgeInsets.only(top: 16, left: 20, right: 20, bottom: 12);
static const double footerButtonSize = 30;
static const double footerButtonInnerSize = 26;
@ -163,7 +163,8 @@ class _PageCardState extends ReactiveState<PageCard> {
Expanded(
flex: 1,
child: c.isLoading.value
? SkeletonParagraph(
? ClipRect(
child: SkeletonParagraph(
style: SkeletonParagraphStyle(
lines: 3,
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 0),
@ -171,6 +172,7 @@ class _PageCardState extends ReactiveState<PageCard> {
randomLength: true,
height: Styles.pageCardDescription.fontSize! * textScale),
),
),
)
: Text(c.pageInfo.value?.description ?? "没有简介",
overflow: TextOverflow.fade, style: Styles.pageCardDescription),

@ -28,8 +28,7 @@ class RecentPageListController extends GetxController {
@override
void onInit() {
scrollController?.addListener(() {
if (scrollController!.position.pixels >
scrollController!.position.maxScrollExtent - 10) {
if (scrollController!.position.pixels > scrollController!.position.maxScrollExtent - 10) {
//
if (hasNextPage.value && !isLoading.value) {
loadNextPages();
@ -73,8 +72,7 @@ class RecentPageListController extends GetxController {
try {
var rcListRes = await MWApiList.getMixedRecentChanges(
limit: 10,
continueInfo: continueInfo.isNotEmpty ? continueInfo : null);
limit: 10, continueInfo: continueInfo.isNotEmpty ? continueInfo : null);
var pageIds = rcListRes.data.map((rcInfo) => rcInfo.pageid).toList();
var pageListRes = await MWApiList.getPageInfoList(
@ -95,7 +93,7 @@ class RecentPageListController extends GetxController {
}
hasNextPage.value = rcListRes.continueInfo != null;
continueInfo.value = rcListRes.continueInfo ?? {};
} catch (err) {
} catch (err, stack) {
hasNextPage.value = false;
if (shouldRefresh) {
pageList.clear();
@ -128,14 +126,13 @@ class RecentPageList extends StatelessWidget {
return Column(
key: key,
children: [
for (var i = 0; i < 6; i++)
PageCard(key: ValueKey("rpl-card-$i"), isLoading: true),
for (var i = 0; i < 6; i++) PageCard(key: ValueKey("rpl-card-$i"), isLoading: true),
],
);
}
Widget _buildPageCard(int index, PageInfo pageInfo,
RecentPageListController c, FavoriteListController fc) {
Widget _buildPageCard(
int index, PageInfo pageInfo, RecentPageListController c, FavoriteListController fc) {
return PageCard(
key: ValueKey("rpl-card-$index"),
pageInfo: c.pageList[index],
@ -153,11 +150,13 @@ class RecentPageList extends StatelessWidget {
(context, index) {
if (index == 0) {
//
return Obx(() {
if (c.pageList.isEmpty) {
return _buildSkeletonList();
} else {
return _buildPageCard(index, c.pageList[index], c, flc);
}
});
}
//
@ -168,7 +167,8 @@ class RecentPageList extends StatelessWidget {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Center(
child: c.isLoading.value
child: Obx(
() => c.isLoading.value
? const CupertinoActivityIndicator(
radius: 14,
)
@ -177,6 +177,7 @@ class RecentPageList extends StatelessWidget {
height: 28,
),
),
),
);
}

@ -235,17 +235,19 @@ class UserController extends GetxController {
}
Future<void> logout({bool logoutRemote = true}) async {
if (logoutRemote) {
authProcessing.value = true;
try {
await MWApiUser.logout();
} catch (err, stack) {
authProcessing.value = false;
alert(Get.overlayContext!, ErrorUtils.getErrorMessage(err), title: "错误");
if (kDebugMode) {
print("Exception in logout: $err");
stack.printError();
}
return;
}
}
// Cookie
@ -255,9 +257,9 @@ class UserController extends GetxController {
userId.value = 0;
userName.value = "";
nickName.value = "";
avatarUrlSet.clear();
avatarUrlSet.value = {};
authProcessing.value = true;
authProcessing.value = false;
saveToStorage();
}

@ -16,8 +16,7 @@ import '../styles.dart';
enum HomeTabs { newest, followed }
class HomeController extends GetxController
with GetSingleTickerProviderStateMixin {
class HomeController extends GetxController with GetSingleTickerProviderStateMixin {
double _navSearchButtonOffset = 90;
var showNavSearchButton = false.obs;
@ -36,15 +35,12 @@ class HomeController extends GetxController
void onInit() {
tabController = TabController(length: 2, vsync: this);
_navSearchButtonOffset =
48 * MediaQuery.of(Get.context!).textScaleFactor + 48;
_navSearchButtonOffset = 48 * MediaQuery.of(Get.context!).textScaleFactor + 48;
scrollController.addListener(() {
if (scrollController.offset >= _navSearchButtonOffset &&
!showNavSearchButton.value) {
if (scrollController.offset >= _navSearchButtonOffset && !showNavSearchButton.value) {
showNavSearchButton.value = true;
} else if (scrollController.offset < _navSearchButtonOffset &&
showNavSearchButton.value) {
} else if (scrollController.offset < _navSearchButtonOffset && showNavSearchButton.value) {
showNavSearchButton.value = false;
}
});
@ -102,11 +98,8 @@ class HomeTab extends StatelessWidget {
duration: const Duration(milliseconds: 100),
child: CupertinoButton(
padding: EdgeInsets.zero,
child: const Icon(CupertinoIcons.search,
size: 26, color: Styles.themeNavTitleColor),
onPressed: () {
onSearchClick?.call();
},
child: const Icon(CupertinoIcons.bell, size: 26, color: Styles.themeNavTitleColor),
onPressed: () {},
),
),
);
@ -121,8 +114,7 @@ class HomeTab extends StatelessWidget {
duration: const Duration(milliseconds: 100),
child: CupertinoButton(
padding: EdgeInsets.zero,
child: const Icon(CupertinoIcons.search,
size: 26, color: Styles.themeNavTitleColor),
child: const Icon(CupertinoIcons.search, size: 26, color: Styles.themeNavTitleColor),
onPressed: () {
onSearchClick?.call();
},
@ -144,13 +136,12 @@ class HomeTab extends StatelessWidget {
),
slivers: <Widget>[
IsekaiSliverNavigationBar(
leading: _buildNotificationIconButton(),
leading: _buildSearchIconButton(),
backgroundColor: Styles.themeMainColor,
brightness: Brightness.dark,
largeTitle: const Text('首页',
style: TextStyle(color: Styles.themeNavTitleColor)),
largeTitle: const Text('首页', style: TextStyle(color: Styles.themeNavTitleColor)),
border: Border.all(style: BorderStyle.none),
trailing: _buildSearchIconButton(),
trailing: _buildNotificationIconButton(),
),
SliverPersistentHeader(
delegate: _SliverAppBarDelegate(
@ -181,12 +172,10 @@ class HomeTab extends StatelessWidget {
children: [
Container(
padding: const EdgeInsets.all(1),
child: const Icon(CupertinoIcons.search,
color: Colors.black54),
child: const Icon(CupertinoIcons.search, color: Colors.black54),
),
const Text("搜索页面...",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.black54))
textAlign: TextAlign.center, style: TextStyle(color: Colors.black54))
],
),
),
@ -216,10 +205,7 @@ class HomeTab extends StatelessWidget {
indicatorColor: Styles.themeMainColor,
labelColor: Styles.themeMainColor,
unselectedLabelColor: Colors.black45,
tabs: const [
CollapsedTabText('最新'),
CollapsedTabText('关注')
],
tabs: const [CollapsedTabText('最新'), CollapsedTabText('关注')],
onTap: (int selected) {},
),
),
@ -264,8 +250,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
double get maxExtent => max(maxHeight, minHeight);
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
return SizedBox.expand(child: child);
}

@ -39,7 +39,7 @@ abstract class Styles {
static const TextStyle pageCardDescription = TextStyle(
color: Colors.black54,
fontSize: 16,
fontSize: 14,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
);

Loading…
Cancel
Save