mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-17 09:54:19 +01:00
fix windows can't open website bug
This commit is contained in:
@@ -40,7 +40,7 @@ class WebProvider extends ChangeNotifier {
|
||||
return StringUtil.rndNameStr(10);
|
||||
}
|
||||
|
||||
void updateWebInfo(WebInfo webInfo) {
|
||||
void updateWebInfo(WebInfo webInfo, {bool updateUI = true}) {
|
||||
for (var i = 0; i < webInfos.length; i++) {
|
||||
var owi = webInfos[i];
|
||||
if (owi.id == webInfo.id) {
|
||||
@@ -49,7 +49,9 @@ class WebProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
if (updateUI) {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
WebInfo? currentWebInfo() {
|
||||
@@ -238,7 +240,7 @@ class WebProvider extends ChangeNotifier {
|
||||
|
||||
Map<String, IndexWebComponent> indexWebviews = {};
|
||||
|
||||
List<Widget> getIndexWebviews(BuildContext context, Function showControl) {
|
||||
List<Widget> getIndexWebviews(BuildContext context) {
|
||||
List<Widget> list = [];
|
||||
for (var webInfo in webInfos) {
|
||||
if (StringUtil.isBlank(webInfo.url)) {
|
||||
@@ -246,8 +248,7 @@ class WebProvider extends ChangeNotifier {
|
||||
} else {
|
||||
var indexWebComp = indexWebviews[webInfo.id];
|
||||
if (indexWebComp == null) {
|
||||
indexWebComp =
|
||||
IndexWebComponent(webInfo, showControl, key: GlobalKey());
|
||||
indexWebComp = IndexWebComponent(webInfo, key: GlobalKey());
|
||||
indexWebviews[webInfo.id] = indexWebComp;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:nowser/component/image_component.dart';
|
||||
import 'package:nowser/component/webview/web_home_component.dart';
|
||||
import 'package:nowser/main.dart';
|
||||
import 'package:nowser/provider/web_provider.dart';
|
||||
import 'package:nowser/router/index/index_web_bottom_component.dart';
|
||||
import 'package:nowser/router/index/index_web_component.dart';
|
||||
import 'package:nowser/util/router_util.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -100,7 +101,7 @@ class _IndexRouter extends CustState<IndexRouter>
|
||||
|
||||
var main = IndexedStack(
|
||||
index: _webProvider.index,
|
||||
children: _webProvider.getIndexWebviews(context, showControl),
|
||||
children: _webProvider.getIndexWebviews(context),
|
||||
);
|
||||
|
||||
return PopScope(
|
||||
@@ -125,7 +126,12 @@ class _IndexRouter extends CustState<IndexRouter>
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
statusBarBrightness: Brightness.light,
|
||||
),
|
||||
child: main,
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(child: main),
|
||||
IndexWebBottomComponent(showControl),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/component/webview/web_info.dart';
|
||||
import 'package:nowser/provider/web_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../component/webview/webview_number_component.dart';
|
||||
import '../../const/base.dart';
|
||||
import '../../const/router_path.dart';
|
||||
import '../../main.dart';
|
||||
import '../../util/router_util.dart';
|
||||
|
||||
class IndexWebBottomComponent extends StatefulWidget {
|
||||
Function showControl;
|
||||
|
||||
IndexWebBottomComponent(this.showControl);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _IndexWebBottomComponent();
|
||||
@@ -10,6 +24,114 @@ class IndexWebBottomComponent extends StatefulWidget {
|
||||
class _IndexWebBottomComponent extends State<IndexWebBottomComponent> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
var mediaQuery = MediaQuery.of(context);
|
||||
var padding = mediaQuery.padding;
|
||||
var maxWidth = mediaQuery.size.width;
|
||||
var titleWidth = maxWidth / 2;
|
||||
|
||||
return Selector<WebProvider, WebInfo?>(builder: (context, webInfo, child) {
|
||||
if (webInfo == null || StringUtil.isBlank(webInfo.url)) {
|
||||
return Container();
|
||||
}
|
||||
|
||||
String title = "";
|
||||
if (StringUtil.isNotBlank(webInfo.title)) {
|
||||
title = webInfo.title!;
|
||||
} else if (StringUtil.isNotBlank(webInfo.url)) {
|
||||
title = webInfo.url;
|
||||
}
|
||||
Widget numberWidget = WebViewNumberComponent();
|
||||
|
||||
return Container(
|
||||
height: 60,
|
||||
child: Row(
|
||||
children: [
|
||||
wrapBottomBtn(const Icon(Icons.home_filled), left: 13, right: 8,
|
||||
onTap: () {
|
||||
webProvider.goHome(webInfo);
|
||||
}),
|
||||
wrapBottomBtn(numberWidget, left: 8, right: 8, onTap: () {
|
||||
RouterUtil.router(context, RouterPath.WEB_TABS);
|
||||
}),
|
||||
Expanded(
|
||||
child: Hero(
|
||||
tag: "urlInput",
|
||||
child: Material(
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
if (webInfo.controller == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var url = await webInfo.controller!.getUrl();
|
||||
var urlStr = url.toString();
|
||||
if (StringUtil.isBlank(urlStr) || urlStr == "null") {
|
||||
urlStr = webInfo.url;
|
||||
}
|
||||
var value = await RouterUtil.router(
|
||||
context, RouterPath.WEB_URL_INPUT, urlStr);
|
||||
if (value != null && value is String) {
|
||||
webProvider.goTo(webInfo, value);
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(
|
||||
left: 8,
|
||||
right: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(),
|
||||
borderRadius:
|
||||
BorderRadius.circular(Base.BASE_PADDING_HALF),
|
||||
),
|
||||
padding: const EdgeInsets.only(
|
||||
left: Base.BASE_PADDING,
|
||||
right: Base.BASE_PADDING,
|
||||
top: Base.BASE_PADDING_HALF,
|
||||
bottom: Base.BASE_PADDING_HALF,
|
||||
),
|
||||
width: titleWidth,
|
||||
child: Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
wrapBottomBtn(const Icon(Icons.space_dashboard), onTap: () {
|
||||
widget.showControl();
|
||||
}, left: 8, right: 8),
|
||||
wrapBottomBtn(const Icon(Icons.segment), left: 8, right: 13,
|
||||
onTap: () {
|
||||
RouterUtil.router(context, RouterPath.ME);
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
}, selector: (context, provider) {
|
||||
return provider.currentWebInfo();
|
||||
});
|
||||
}
|
||||
|
||||
Widget wrapBottomBtn(Widget btn,
|
||||
{double left = 10, double right = 10, Function? onTap}) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (onTap != null) {
|
||||
onTap();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: left,
|
||||
right: right,
|
||||
),
|
||||
child: btn,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,7 @@ import 'web_control_component.dart';
|
||||
class IndexWebComponent extends StatefulWidget {
|
||||
WebInfo webInfo;
|
||||
|
||||
Function showControl;
|
||||
|
||||
IndexWebComponent(this.webInfo, this.showControl, {required GlobalKey key})
|
||||
: super(key: key);
|
||||
IndexWebComponent(this.webInfo, {required GlobalKey key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@@ -50,7 +47,6 @@ class _IndexWebComponent extends State<IndexWebComponent> {
|
||||
var maxWidth = mediaQuery.size.width;
|
||||
var titleWidth = maxWidth / 2;
|
||||
|
||||
Widget numberWidget = WebViewNumberComponent();
|
||||
var webInfo = widget.webInfo;
|
||||
|
||||
if (StringUtil.isBlank(webInfo.url)) {
|
||||
@@ -69,88 +65,7 @@ class _IndexWebComponent extends State<IndexWebComponent> {
|
||||
webProvider.onLoadStop(webInfo);
|
||||
});
|
||||
|
||||
String title = "";
|
||||
if (StringUtil.isNotBlank(webInfo.title)) {
|
||||
title = webInfo.title!;
|
||||
} else if (StringUtil.isNotBlank(webInfo.url)) {
|
||||
title = webInfo.url;
|
||||
}
|
||||
|
||||
var main = Column(
|
||||
children: [
|
||||
Expanded(child: webComp),
|
||||
Container(
|
||||
height: 60,
|
||||
child: Row(
|
||||
children: [
|
||||
wrapBottomBtn(const Icon(Icons.home_filled), left: 13, right: 8,
|
||||
onTap: () {
|
||||
webProvider.goHome(webInfo);
|
||||
}),
|
||||
wrapBottomBtn(numberWidget, left: 8, right: 8, onTap: () {
|
||||
RouterUtil.router(context, RouterPath.WEB_TABS);
|
||||
}),
|
||||
Expanded(
|
||||
child: Hero(
|
||||
tag: "urlInput",
|
||||
child: Material(
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
if (webInfo.controller == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var url = await webInfo.controller!.getUrl();
|
||||
var urlStr = url.toString();
|
||||
if (StringUtil.isBlank(urlStr) || urlStr == "null") {
|
||||
urlStr = webInfo.url;
|
||||
}
|
||||
var value = await RouterUtil.router(
|
||||
context, RouterPath.WEB_URL_INPUT, urlStr);
|
||||
if (value != null && value is String) {
|
||||
webProvider.goTo(webInfo, value);
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(
|
||||
left: 8,
|
||||
right: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(),
|
||||
borderRadius:
|
||||
BorderRadius.circular(Base.BASE_PADDING_HALF),
|
||||
),
|
||||
padding: const EdgeInsets.only(
|
||||
left: Base.BASE_PADDING,
|
||||
right: Base.BASE_PADDING,
|
||||
top: Base.BASE_PADDING_HALF,
|
||||
bottom: Base.BASE_PADDING_HALF,
|
||||
),
|
||||
width: titleWidth,
|
||||
child: Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
wrapBottomBtn(const Icon(Icons.space_dashboard), onTap: () {
|
||||
widget.showControl();
|
||||
}, left: 8, right: 8),
|
||||
wrapBottomBtn(const Icon(Icons.segment), left: 8, right: 13,
|
||||
onTap: () {
|
||||
RouterUtil.router(context, RouterPath.ME);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
var main = webComp;
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
@@ -166,25 +81,5 @@ class _IndexWebComponent extends State<IndexWebComponent> {
|
||||
webInfo.controller = controller;
|
||||
webInfo.title = title;
|
||||
webProvider.updateWebInfo(webInfo);
|
||||
// TODO this setState will make windows's webview alway refresh !
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Widget wrapBottomBtn(Widget btn,
|
||||
{double left = 10, double right = 10, Function? onTap}) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (onTap != null) {
|
||||
onTap();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: left,
|
||||
right: right,
|
||||
),
|
||||
child: btn,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user