mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-18 10:04:20 +01:00
bugfix
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/utils/platform_util.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/component/cust_state.dart';
|
||||
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_component.dart';
|
||||
@@ -23,7 +28,10 @@ class _IndexRouter extends CustState<IndexRouter>
|
||||
with PermissionCheckMixin, AndroidSignerMixin {
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||
|
||||
Map<String, WebViewComponent> webViewComponentMap = {};
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onReady(BuildContext context) async {
|
||||
@@ -41,19 +49,12 @@ class _IndexRouter extends CustState<IndexRouter>
|
||||
remoteSigningProvider.updateContext(context);
|
||||
webProvider.checkBlank();
|
||||
|
||||
var main = Selector<WebProvider, WebNumInfo>(
|
||||
builder: (context, webNumInfo, child) {
|
||||
List<Widget> list = [];
|
||||
for (var i = 0; i < webNumInfo.length; i++) {
|
||||
list.add(IndexWebComponent(i, showControl));
|
||||
}
|
||||
return IndexedStack(
|
||||
index: webNumInfo.index,
|
||||
children: list,
|
||||
);
|
||||
}, selector: (context, provider) {
|
||||
return provider.getWebNumInfo();
|
||||
});
|
||||
var _webProvider = Provider.of<WebProvider>(context);
|
||||
|
||||
var main = IndexedStack(
|
||||
index: _webProvider.index,
|
||||
children: _webProvider.getIndexWebviews(context, showControl),
|
||||
);
|
||||
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
|
||||
@@ -15,11 +15,12 @@ import '../../component/webview/webview_number_component.dart';
|
||||
import 'web_control_component.dart';
|
||||
|
||||
class IndexWebComponent extends StatefulWidget {
|
||||
int index;
|
||||
WebInfo webInfo;
|
||||
|
||||
Function showControl;
|
||||
|
||||
IndexWebComponent(this.index, this.showControl);
|
||||
IndexWebComponent(this.webInfo, this.showControl, {required GlobalKey key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@@ -30,6 +31,18 @@ class IndexWebComponent extends StatefulWidget {
|
||||
class _IndexWebComponent extends State<IndexWebComponent> {
|
||||
static const double BOTTOM_BTN_PADDING = 10;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// print("indexWebComp initState ${widget.webInfo.id}");
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
// print("indexWebComp dispose ${widget.webInfo.id}");
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var mediaQuery = MediaQuery.of(context);
|
||||
@@ -38,120 +51,120 @@ class _IndexWebComponent extends State<IndexWebComponent> {
|
||||
var titleWidth = maxWidth / 2;
|
||||
|
||||
Widget numberWidget = WebViewNumberComponent();
|
||||
var webInfo = widget.webInfo;
|
||||
|
||||
if (StringUtil.isBlank(webInfo.url)) {
|
||||
return WebHomeComponent(webInfo);
|
||||
}
|
||||
|
||||
var webComp = WebViewComponent(
|
||||
webInfo,
|
||||
(webInfo, controller) {
|
||||
webInfo.controller = controller;
|
||||
webProvider.updateWebInfo(webInfo);
|
||||
},
|
||||
onTitleChanged,
|
||||
(webInfo, controller) {
|
||||
webInfo.controller = controller;
|
||||
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 value = await RouterUtil.router(
|
||||
context, RouterPath.WEB_URL_INPUT, url.toString());
|
||||
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);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
top: padding.top,
|
||||
bottom: padding.bottom,
|
||||
),
|
||||
child: Selector<WebProvider, WebInfo?>(
|
||||
builder: (context, webInfo, child) {
|
||||
if (webInfo == null || StringUtil.isBlank(webInfo.url)) {
|
||||
if (webInfo == null) {
|
||||
return Container();
|
||||
}
|
||||
|
||||
return WebHomeComponent(webInfo);
|
||||
}
|
||||
|
||||
var main = WebViewComponent(webInfo, (webInfo, controller) {
|
||||
webInfo.controller = controller;
|
||||
webProvider.updateWebInfo(webInfo);
|
||||
}, (webInfo, controller, title) {
|
||||
webInfo.controller = controller;
|
||||
webInfo.title = title;
|
||||
webProvider.updateWebInfo(webInfo);
|
||||
}, (webInfo, controller) {
|
||||
webInfo.controller = controller;
|
||||
webProvider.onLoadStop(webInfo);
|
||||
});
|
||||
|
||||
String title = "";
|
||||
if (StringUtil.isNotBlank(webInfo.title)) {
|
||||
title = webInfo.title!;
|
||||
} else if (StringUtil.isNotBlank(webInfo.url)) {
|
||||
title = webInfo.url;
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(child: main),
|
||||
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 value = await RouterUtil.router(context,
|
||||
RouterPath.WEB_URL_INPUT, url.toString());
|
||||
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.getWebInfo(widget.index);
|
||||
},
|
||||
),
|
||||
child: main,
|
||||
);
|
||||
}
|
||||
|
||||
void onTitleChanged(
|
||||
WebInfo webInfo, InAppWebViewController controller, String? title) {
|
||||
webInfo.controller = controller;
|
||||
webInfo.title = title;
|
||||
webProvider.updateWebInfo(webInfo);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Widget wrapBottomBtn(Widget btn,
|
||||
{double left = 10, double right = 10, Function? onTap}) {
|
||||
return GestureDetector(
|
||||
|
||||
Reference in New Issue
Block a user