feat: 分类页面优化,播放器详情处理当前集,首页的优化。图片导入。
This commit is contained in:
1 parent
4ccea08472
commit
2f1ec27802
28 files changed
+868
-568
No files matched your search
+67
-371
@@ -1,7 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:skywood/global/client/user_client.dart';
|
||||
import 'package:skywood/global/request/api_const.dart';
|
||||
import 'package:skywood/main/lib_file.dart';
|
||||
import 'package:skywood/pages/mine/page/about_us_page.dart';
|
||||
import 'package:skywood/pages/mine/page/sky_web_page.dart';
|
||||
import 'package:skywood/pages/mine/widget/mine_section_view.dart';
|
||||
import 'package:skywood/pages/widgets/pixel_widgets.dart';
|
||||
import 'package:skywood/utils/models/user/skywood_user.dart';
|
||||
@@ -23,6 +26,40 @@ class _MainRootState extends State<MinePage> {
|
||||
|
||||
SkywoodUser? _userInfo;
|
||||
|
||||
List<Widget> _buildSections() {
|
||||
final menuData = [
|
||||
{
|
||||
'title': 'Privacy Policy', 'img': ConstImg.minePp,
|
||||
'action': () {
|
||||
HelpNav.to(SkyWebPage(params: WebLinkParams(
|
||||
title: 'Privacy Policy',
|
||||
urlString: ApiConst.webPrivacy,
|
||||
)));
|
||||
}
|
||||
},
|
||||
{
|
||||
'title': 'User Agreement', 'img': ConstImg.mineUa,
|
||||
'action': () {
|
||||
HelpNav.to(SkyWebPage(params: WebLinkParams(
|
||||
title: 'User Agreement',
|
||||
urlString: ApiConst.webAgreement,
|
||||
)));
|
||||
}
|
||||
},
|
||||
{
|
||||
'title': 'About us', 'img': ConstImg.mineAb,
|
||||
'action': () {
|
||||
HelpNav.to(AboutUsPage());
|
||||
}
|
||||
}
|
||||
];
|
||||
return menuData.map((ele) => _buildMenuItem(
|
||||
ele['title'] as String,
|
||||
imgName: ele['img'] as String,
|
||||
onTap: ele['action'] as void Function(),
|
||||
)).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -54,7 +91,22 @@ class _MainRootState extends State<MinePage> {
|
||||
child: _userInfo==null ? null : _showUserInfo(),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
MineSectionView(title: 'GAME MENU', imgName: ConstImg.sectionBg1),
|
||||
MineSectionView(title: 'GAME MENU', imgName: ConstImg.sectionBg1,
|
||||
paddingSpace: 10,
|
||||
child: SizedBox(
|
||||
height: 200,
|
||||
child: GridView.builder(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 4,
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
childAspectRatio: 1.0,
|
||||
),
|
||||
itemBuilder: (context, index) => _buildSections()[index],
|
||||
itemCount: _buildSections().length,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
@@ -106,384 +158,28 @@ class _MainRootState extends State<MinePage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 15.w),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
Widget _buildMenuItem(String title, {required String imgName, Function()? onTap}) {
|
||||
double _w = (AppScreen.screenWidth - 30 - 10) / 4 - 10;
|
||||
return Stack(
|
||||
children: [
|
||||
HelpImg.asset(ConstImg.mineBtnBg, width: _w, fit: BoxFit.fill),
|
||||
Positioned(
|
||||
left: 5, top: 5, right: 5,
|
||||
child: Column(
|
||||
children: [
|
||||
_DecorIcon(icon: Icons.forest, color: const Color(0xFFFF5454)),
|
||||
SizedBox(width: 10.w),
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 60.h,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF16ED1E),
|
||||
border: Border.all(color: CommonColor.black, width: 1.5.w),
|
||||
boxShadow: const [
|
||||
BoxShadow(color: Color(0xFF1C1E1F), offset: Offset(3, 3)),
|
||||
],
|
||||
),
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 24.sp,
|
||||
fontWeight: FontWeight.w900,
|
||||
height: 1,
|
||||
shadows: const [
|
||||
Shadow(
|
||||
color: Color(0xFF1C1E1F),
|
||||
offset: Offset(2, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
children: const [
|
||||
TextSpan(
|
||||
text: 'Profile ',
|
||||
style: TextStyle(color: Color(0xFFFFDC4C)),
|
||||
),
|
||||
TextSpan(
|
||||
text: 'Menu',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
HelpImg.asset(imgName, width: _w/2.0),
|
||||
SkyText(text: title, fontSize: 9, color: Colors.white,
|
||||
maxLines: 2,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
SizedBox(width: 10.w),
|
||||
_DecorIcon(icon: Icons.live_tv, color: const Color(0xFF8965FB)),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 12.h),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(7, (index) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 3.w),
|
||||
child: Icon(
|
||||
index < 4 ? Icons.favorite : Icons.question_mark,
|
||||
size: index < 4 ? 18.w : 14.w,
|
||||
color: index.isEven
|
||||
? const Color(0xFF1AF23A)
|
||||
: const Color(0xFF653CFA),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPlayerCard() {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 15.w),
|
||||
child: PixelPanel(
|
||||
color: CommonColor.primacyColor,
|
||||
shadowColor: CommonColor.black,
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
const PixelSectionLabel(label: 'Player Card'),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(16.w),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 68.w,
|
||||
height: 68.w,
|
||||
padding: EdgeInsets.all(4.w),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFE9C7FF),
|
||||
border: Border.all(color: CommonColor.black, width: 1.w),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.person_pin,
|
||||
size: 42.w,
|
||||
color: const Color(0xFF653CFA),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 15.w),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Vistor',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20.sp,
|
||||
fontWeight: FontWeight.w700,
|
||||
height: 1,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12.h),
|
||||
Text(
|
||||
'ID: 32432233341',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.72),
|
||||
fontSize: 10.sp,
|
||||
height: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWalletShop() {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 15.w),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _SmallPanel(
|
||||
label: 'Treasure Wallet',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.inventory_2,
|
||||
size: 70.w,
|
||||
color: const Color(0xFFFFDC4C),
|
||||
),
|
||||
SizedBox(width: 6.w),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_WalletValue(label: 'Coins', value: '15,890'),
|
||||
Divider(height: 8.h, color: Colors.white54),
|
||||
_WalletValue(label: 'Bonus', value: '20,000'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10.w),
|
||||
Expanded(
|
||||
child: _SmallPanel(
|
||||
label: 'Item Shop',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.storefront,
|
||||
size: 66.w,
|
||||
color: const Color(0xFFFF8DB8),
|
||||
),
|
||||
SizedBox(width: 7.w),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Get More\nCoins',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12.sp,
|
||||
fontWeight: FontWeight.w600,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 14.h),
|
||||
const PixelButton(
|
||||
label: 'Store',
|
||||
width: 70,
|
||||
height: 20,
|
||||
color: Color(0xFFFF88CF),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCheckpoint() {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 15.w),
|
||||
child: PixelPanel(
|
||||
color: CommonColor.primacyColor,
|
||||
padding: EdgeInsets.zero,
|
||||
shadowColor: CommonColor.black,
|
||||
child: Column(
|
||||
children: [
|
||||
const PixelSectionLabel(label: 'Daily Checkpoint'),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(16.w, 10.h, 10.w, 10.h),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: List.generate(7, (index) {
|
||||
return _DayBox(day: index + 1, active: index == 0);
|
||||
}),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 12.w),
|
||||
const PixelButton(
|
||||
label: 'Check In',
|
||||
width: 70,
|
||||
height: 22,
|
||||
color: Color(0xFFFF88CF),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGameMenu() {
|
||||
final items = const [
|
||||
_MenuItem('Log In', Icons.login),
|
||||
_MenuItem('Wallet', Icons.account_balance_wallet),
|
||||
_MenuItem('Language', Icons.public),
|
||||
_MenuItem('Feedback', Icons.mail),
|
||||
_MenuItem('Settings', Icons.settings),
|
||||
_MenuItem('About Us', Icons.info),
|
||||
];
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 15.w),
|
||||
child: PixelPanel(
|
||||
color: CommonColor.primacyColor,
|
||||
padding: EdgeInsets.zero,
|
||||
shadowColor: CommonColor.black,
|
||||
child: Column(
|
||||
children: [
|
||||
const PixelSectionLabel(label: 'Game Menu'),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(10.w),
|
||||
child: GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 5,
|
||||
mainAxisSpacing: 8.h,
|
||||
crossAxisSpacing: 6.w,
|
||||
childAspectRatio: 1,
|
||||
),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (context, index) => _MenuTile(item: items[index]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SmallPanel extends StatelessWidget {
|
||||
const _SmallPanel({required this.label, required this.child});
|
||||
|
||||
final String label;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PixelPanel(
|
||||
color: CommonColor.primacyColor,
|
||||
shadowColor: CommonColor.black,
|
||||
padding: EdgeInsets.zero,
|
||||
child: SizedBox(
|
||||
height: 134.h,
|
||||
child: Column(
|
||||
children: [
|
||||
PixelSectionLabel(label: label),
|
||||
Expanded(
|
||||
child: Padding(padding: EdgeInsets.all(8.w), child: child),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _WalletValue extends StatelessWidget {
|
||||
const _WalletValue({required this.label, required this.value});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(color: Colors.white70, fontSize: 9.sp, height: 1),
|
||||
),
|
||||
SizedBox(height: 2.h),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15.sp,
|
||||
fontWeight: FontWeight.w900,
|
||||
height: 1,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
).addInkWell(onTap: onTap);
|
||||
}
|
||||
}
|
||||
|
||||
class _DayBox extends StatelessWidget {
|
||||
const _DayBox({required this.day, required this.active});
|
||||
|
||||
final int day;
|
||||
final bool active;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 28.w,
|
||||
height: 34.h,
|
||||
decoration: BoxDecoration(
|
||||
color: active ? const Color(0xFF91F473) : Colors.white,
|
||||
border: Border.all(color: CommonColor.black, width: 1.w),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('Day', style: TextStyle(fontSize: 7.sp, height: 1)),
|
||||
SizedBox(height: 4.h),
|
||||
Text(
|
||||
'$day',
|
||||
style: TextStyle(
|
||||
fontSize: 14.sp,
|
||||
fontWeight: FontWeight.w800,
|
||||
height: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MenuTile extends StatelessWidget {
|
||||
const _MenuTile({required this.item});
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:skywood/global/request/api_const.dart';
|
||||
import 'package:skywood/utils/tools/sky_device_info.dart';
|
||||
import 'package:skywood/utils/tools/widgets/sky_app_bar.dart';
|
||||
import 'package:skywood/utils/tools/widgets/sky_common_widget.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class AboutUsPage extends StatelessWidget {
|
||||
|
||||
const AboutUsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: SkyAppBar(
|
||||
title: 'About Us',
|
||||
),
|
||||
body: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 100),
|
||||
SkyText(text: ApiConst.appName,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
SkyText(text: 'V ${SkyDeviceInfo.instance.appVersion}',
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Container(
|
||||
height: 46,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> openUrl(String url) async {
|
||||
final encodedUrl = Uri.encodeFull(url);
|
||||
try {
|
||||
final bool launched = await launchUrl(
|
||||
Uri.parse(encodedUrl),
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
if (!launched) {
|
||||
print('无法打开链接: $encodedUrl');
|
||||
}
|
||||
} catch (e) {
|
||||
print('打开链接异常: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:loading_animation_widget/loading_animation_widget.dart';
|
||||
import 'package:skywood/utils/tools/widgets/sky_app_bar.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
/// WebView 页面参数
|
||||
class WebLinkParams {
|
||||
final String title;
|
||||
final String urlString;
|
||||
final bool showAppbar;
|
||||
|
||||
const WebLinkParams({
|
||||
this.title = 'Web View',
|
||||
required this.urlString,
|
||||
this.showAppbar = true,
|
||||
});
|
||||
}
|
||||
|
||||
/// WebView 页面
|
||||
class SkyWebPage extends StatefulWidget {
|
||||
final WebLinkParams params;
|
||||
|
||||
const SkyWebPage({
|
||||
super.key,
|
||||
required this.params,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SkyWebPage> createState() => _WebLinkViewState();
|
||||
}
|
||||
|
||||
class _WebLinkViewState extends State<SkyWebPage> {
|
||||
late WebViewController _webViewController;
|
||||
int _loadingProgress = 0;
|
||||
bool _isLoading = true;
|
||||
bool _hasError = false;
|
||||
String _errorMessage = '';
|
||||
String _urlString = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initializeParameters();
|
||||
_initializeWebView();
|
||||
_loadUrl();
|
||||
}
|
||||
|
||||
void _initializeParameters() {
|
||||
_urlString = _validateAndFixUrl(widget.params.urlString);
|
||||
}
|
||||
|
||||
void _initializeWebView() {
|
||||
_webViewController = WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..setBackgroundColor(const Color(0x00FF0000))
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
onProgress: (int progress) {
|
||||
setState(() {
|
||||
_loadingProgress = progress;
|
||||
});
|
||||
},
|
||||
onPageStarted: (String url) {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_hasError = false;
|
||||
_loadingProgress = 0;
|
||||
});
|
||||
},
|
||||
onPageFinished: (String url) async {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_loadingProgress = 100;
|
||||
});
|
||||
|
||||
// 修改网页背景为透明,文字为白色
|
||||
await _webViewController.runJavaScript('''
|
||||
document.body.style.background = 'none';
|
||||
document.body.style.color = '#fff';
|
||||
|
||||
// 修改标题样式
|
||||
var titleElements = document.getElementsByClassName('title');
|
||||
for (var i = 0; i < titleElements.length; i++) {
|
||||
titleElements[i].style.display = 'none';
|
||||
}
|
||||
|
||||
// 修改文本背景为白色
|
||||
var bgElements = document.getElementsByClassName('bg-fff');
|
||||
for (var i = 0; i < bgElements.length; i++) {
|
||||
bgElements[i].style.background = 'none';
|
||||
bgElements[i].style.paddingTop = '0px';
|
||||
}
|
||||
|
||||
// 修改所有文本元素为白色
|
||||
var allElements = document.getElementsByTagName('*');
|
||||
for (var i = 0; i < allElements.length; i++) {
|
||||
allElements[i].style.color = '#fff';
|
||||
}
|
||||
|
||||
// 修改链接颜色
|
||||
var links = document.getElementsByTagName('a');
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
links[i].style.color = '#87CEEB';
|
||||
}
|
||||
''');
|
||||
},
|
||||
onHttpError: (HttpResponseError error) {
|
||||
setState(() {
|
||||
_hasError = true;
|
||||
_errorMessage = 'HTTP Error: ${error.response?.statusCode ?? "Unknown"}';
|
||||
_isLoading = false;
|
||||
});
|
||||
},
|
||||
onWebResourceError: (WebResourceError error) {
|
||||
setState(() {
|
||||
_hasError = true;
|
||||
_errorMessage = error.description;
|
||||
_isLoading = false;
|
||||
});
|
||||
},
|
||||
onNavigationRequest: (NavigationRequest request) {
|
||||
return NavigationDecision.navigate;
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _loadUrl() {
|
||||
if (_urlString.isEmpty) {
|
||||
setState(() {
|
||||
_hasError = true;
|
||||
_errorMessage = 'Invalid URL';
|
||||
_isLoading = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final uri = Uri.parse(_urlString);
|
||||
_webViewController.loadRequest(uri);
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_hasError = true;
|
||||
_errorMessage = 'Failed to load URL: $e';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
String _validateAndFixUrl(String url) {
|
||||
if (url.isEmpty) {
|
||||
return '';
|
||||
}
|
||||
|
||||
url = url.trim();
|
||||
|
||||
// Already has a valid scheme
|
||||
if (url.startsWith('http://') || url.startsWith('https://')) {
|
||||
return url;
|
||||
}
|
||||
|
||||
// Looks like a domain (has a dot and no spaces)
|
||||
if (url.contains('.') && !url.contains(' ')) {
|
||||
return 'https://$url';
|
||||
}
|
||||
|
||||
// Treat as search query
|
||||
return 'https://www.google.com/search?q=${Uri.encodeComponent(url)}';
|
||||
}
|
||||
|
||||
void _reload() {
|
||||
setState(() {
|
||||
_hasError = false;
|
||||
_isLoading = true;
|
||||
_loadingProgress = 0;
|
||||
_errorMessage = '';
|
||||
});
|
||||
_initializeWebView();
|
||||
_loadUrl();
|
||||
}
|
||||
|
||||
void _goBack() {
|
||||
_webViewController.goBack();
|
||||
}
|
||||
|
||||
void _goForward() {
|
||||
_webViewController.goForward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_webViewController.clearCache();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: widget.params.showAppbar
|
||||
? _buildAppBar()
|
||||
: null,
|
||||
body: _buildBody(),
|
||||
);
|
||||
}
|
||||
|
||||
PreferredSizeWidget _buildAppBar() {
|
||||
return SkyAppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
title: widget.params.title,
|
||||
titleColor: Colors.white,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: _reload,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody() {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xFF1A0B2E),
|
||||
Color(0xFF2D1B4E),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// 加载进度条(可选)
|
||||
if (_isLoading)
|
||||
LinearProgressIndicator(
|
||||
value: _loadingProgress / 100,
|
||||
backgroundColor: Colors.white.withOpacity(0.2),
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(
|
||||
Color(0xFFFB98E0),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _buildContent(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent() {
|
||||
if (_isLoading) {
|
||||
return Center(
|
||||
child: LoadingAnimationWidget.newtonCradle(
|
||||
color: const Color(0xFFFB98E0),
|
||||
size: 96.w,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (_hasError) {
|
||||
return _buildErrorWidget();
|
||||
}
|
||||
|
||||
return WebViewWidget(
|
||||
controller: _webViewController,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorWidget() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 64.w,
|
||||
color: Colors.white.withOpacity(0.6),
|
||||
),
|
||||
SizedBox(height: 16.h),
|
||||
Text(
|
||||
_errorMessage,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.8),
|
||||
fontSize: 16.sp,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
SizedBox(height: 24.h),
|
||||
ElevatedButton(
|
||||
onPressed: _reload,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFFFB98E0),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('重试'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user