mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-17 09:54:19 +01:00
url input page
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:nowser/component/auth_dialog/auth_dialog_base_componnet.dart';
|
||||
import 'package:nowser/component/webview/web_info.dart';
|
||||
import 'package:nowser/const/base.dart';
|
||||
import 'package:nowser/main.dart';
|
||||
import 'package:nowser/router/web_url_input/web_url_input_router.dart';
|
||||
|
||||
import '../../const/router_path.dart';
|
||||
import '../../util/router_util.dart';
|
||||
@@ -27,7 +28,7 @@ class _WebHomeComponent extends State<WebHomeComponent> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
textEditingController.text = "https://nostr.build/login/";
|
||||
// textEditingController.text = "https://nostr.build/login/";
|
||||
// textEditingController.text = "https://web.nostrmo.com/";
|
||||
}
|
||||
|
||||
@@ -39,18 +40,28 @@ class _WebHomeComponent extends State<WebHomeComponent> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: TextField(
|
||||
controller: textEditingController,
|
||||
decoration: InputDecoration(border: OutlineInputBorder()),
|
||||
onSubmitted: (value) {
|
||||
print("onSubmitted $value");
|
||||
if (value.startsWith("http")) {
|
||||
widget.webInfo.url = value;
|
||||
widget.webInfo.title = null;
|
||||
child: Hero(
|
||||
tag: "urlInput",
|
||||
child: Material(
|
||||
child: TextField(
|
||||
controller: textEditingController,
|
||||
decoration:
|
||||
const InputDecoration(border: OutlineInputBorder()),
|
||||
readOnly: true,
|
||||
onTap: () async {
|
||||
var value = await RouterUtil.router(
|
||||
context, RouterPath.WEB_URL_INPUT);
|
||||
if (value != null &&
|
||||
value is String &&
|
||||
value.startsWith("http")) {
|
||||
widget.webInfo.url = value;
|
||||
widget.webInfo.title = null;
|
||||
|
||||
webProvider.updateWebInfo(widget.webInfo);
|
||||
}
|
||||
},
|
||||
webProvider.updateWebInfo(widget.webInfo);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class RouterPath {
|
||||
static const String INDEX = "/";
|
||||
static const String WEB_TABS = "/webTabs";
|
||||
static const String WEB_URL_INPUT = "/webUrlInput";
|
||||
static const String ME = "/me";
|
||||
static const String KEYS = "/keys";
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import 'package:nowser/router/index/index_router.dart';
|
||||
import 'package:nowser/router/keys/keys_router.dart';
|
||||
import 'package:nowser/router/me/me_router.dart';
|
||||
import 'package:nowser/router/web_tabs_select/web_tabs_select_router.dart';
|
||||
import 'package:nowser/router/web_url_input/web_url_input_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:receive_intent/receive_intent.dart' as receiveIntent;
|
||||
|
||||
@@ -88,6 +89,7 @@ class _MyApp extends State<MyApp> {
|
||||
routes = {
|
||||
RouterPath.INDEX: (context) => IndexRouter(),
|
||||
RouterPath.WEB_TABS: (context) => WebTabsSelectRouter(),
|
||||
RouterPath.WEB_URL_INPUT: (context) => WebUrlInputRouter(),
|
||||
RouterPath.ME: (context) => MeRouter(),
|
||||
RouterPath.KEYS: (context) => KeysRouter(),
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/component/webview/web_info.dart';
|
||||
import 'package:nowser/component/webview/webview_component.dart';
|
||||
@@ -80,29 +81,60 @@ class _IndexWebComponent extends State<IndexWebComponent> {
|
||||
RouterUtil.router(context, RouterPath.WEB_TABS);
|
||||
}),
|
||||
Expanded(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(
|
||||
left: 8,
|
||||
right: 8,
|
||||
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 &&
|
||||
value.startsWith("http")) {
|
||||
webInfo.url = value;
|
||||
webInfo.title = null;
|
||||
|
||||
if (webInfo.controller != null) {
|
||||
webInfo.controller!.loadUrl(
|
||||
urlRequest: URLRequest(
|
||||
url: WebUri(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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
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),
|
||||
left: 8, right: 8),
|
||||
wrapBottomBtn(const Icon(Icons.segment), left: 8, right: 13,
|
||||
|
||||
58
lib/router/web_url_input/web_url_input_router.dart
Normal file
58
lib/router/web_url_input/web_url_input_router.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nowser/util/router_util.dart';
|
||||
|
||||
import '../../const/base.dart';
|
||||
|
||||
class WebUrlInputRouter extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _WebUrlInputRouter();
|
||||
}
|
||||
}
|
||||
|
||||
class _WebUrlInputRouter extends State<WebUrlInputRouter> {
|
||||
TextEditingController textEditingController = TextEditingController();
|
||||
|
||||
String? url;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (url == null) {
|
||||
var arg = RouterUtil.routerArgs(context);
|
||||
if (arg != null && arg is String) {
|
||||
url = arg;
|
||||
textEditingController.text = arg;
|
||||
}
|
||||
}
|
||||
|
||||
List<Widget> list = [];
|
||||
|
||||
var inputWidget = Hero(
|
||||
tag: "urlInput",
|
||||
child: Material(
|
||||
child: TextField(
|
||||
controller: textEditingController,
|
||||
decoration: const InputDecoration(border: OutlineInputBorder()),
|
||||
autofocus: true,
|
||||
onSubmitted: (value) {
|
||||
RouterUtil.back(context, value);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
list.add(Expanded(child: Container()));
|
||||
list.add(Container(
|
||||
padding: const EdgeInsets.all(Base.BASE_PADDING),
|
||||
child: inputWidget,
|
||||
));
|
||||
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
child: Column(
|
||||
children: list,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user