pikapika/lib/screens/components/ContentError.dart

140 lines
4.5 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
import 'package:flutter/material.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/config/ContentFailedReloadAction.dart';
2021-09-29 23:57:09 +00:00
import 'dart:ui';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/enum/ErrorTypes.dart';
2021-09-29 23:57:09 +00:00
class ContentError extends StatelessWidget {
final Object? error;
final StackTrace? stackTrace;
final Future<void> Function() onRefresh;
const ContentError({
Key? key,
required this.error,
required this.stackTrace,
required this.onRefresh,
}) : super(key: key);
@override
Widget build(BuildContext context) {
var type = errorType("$error");
late String message;
2021-11-02 07:54:34 +00:00
late IconData iconData;
2021-09-29 23:57:09 +00:00
switch (type) {
case ERROR_TYPE_NETWORK:
2021-11-02 07:54:34 +00:00
iconData = Icons.wifi_off_rounded;
2021-09-29 23:57:09 +00:00
message = "连接不上啦, 请检查网络";
break;
case ERROR_TYPE_PERMISSION:
2021-11-02 07:54:34 +00:00
iconData = Icons.highlight_off;
message = "没有权限或路径不可用";
break;
2021-10-22 02:24:39 +00:00
case ERROR_TYPE_TIME:
2021-11-02 07:54:34 +00:00
iconData = Icons.timer_off;
2021-10-22 02:24:39 +00:00
message = "请检查设备时间";
break;
2021-10-27 08:29:19 +00:00
case ERROR_TYPE_UNDER_REVIEW:
2021-11-02 07:54:34 +00:00
iconData = Icons.highlight_off;
2021-10-23 02:59:18 +00:00
message = "资源未审核或不可用";
break;
2021-09-29 23:57:09 +00:00
default:
2021-11-02 07:54:34 +00:00
iconData = Icons.highlight_off;
2021-09-29 23:57:09 +00:00
message = "啊哦, 被玩坏了";
break;
}
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
print("$error");
print("$stackTrace");
var width = constraints.maxWidth;
var height = constraints.maxHeight;
var min = width < height ? width : height;
var iconSize = min / 2.3;
var textSize = min / 16;
var tipSize = min / 20;
var infoSize = min / 30;
if (contentFailedReloadAction ==
ContentFailedReloadAction.TOUCH_LOADER) {
return GestureDetector(
onTap: onRefresh,
child: ListView(
children: [
Container(
height: height,
child: Column(
children: [
Expanded(child: Container()),
Container(
child: Icon(
2021-11-02 07:54:34 +00:00
iconData,
size: iconSize,
color: Colors.grey.shade600,
),
),
Container(height: min / 10),
Container(
padding: EdgeInsets.only(
left: 30,
right: 30,
),
child: Text(
message,
style: TextStyle(fontSize: textSize),
textAlign: TextAlign.center,
),
),
Text('(点击刷新)', style: TextStyle(fontSize: tipSize)),
Container(height: min / 15),
Text('$error', style: TextStyle(fontSize: infoSize)),
Expanded(child: Container()),
],
),
),
],
),
);
}
return RefreshIndicator(
onRefresh: onRefresh,
2021-09-29 23:57:09 +00:00
child: ListView(
children: [
Container(
height: height,
child: Column(
children: [
Expanded(child: Container()),
Container(
child: Icon(
2021-11-02 07:54:34 +00:00
iconData,
2021-09-29 23:57:09 +00:00
size: iconSize,
color: Colors.grey.shade600,
),
),
Container(height: min / 10),
Container(
padding: EdgeInsets.only(
left: 30,
right: 30,
),
child: Text(
message,
style: TextStyle(fontSize: textSize),
textAlign: TextAlign.center,
),
),
Text('(下拉刷新)', style: TextStyle(fontSize: tipSize)),
2021-09-29 23:57:09 +00:00
Container(height: min / 15),
Text('$error', style: TextStyle(fontSize: infoSize)),
Expanded(child: Container()),
],
),
),
],
),
);
},
);
2021-09-29 23:57:09 +00:00
}
}