嗨,我是一名移动应用程序开发人员,对 Web 开发不太熟悉,在加载 Flutter Web 应用程序(如 Gmail 加载屏幕)之前,我正在寻找任何实现进度指示器的方法。Flutter web 很酷,但加载应用程序需要一些时间。我们可以为此加载持续时间添加任何指标吗?在 flutter 中实现的任何代码都将是 flutter app 的一部分,它不会工作,应该有另一种方法来实现这一点。
假设audioplayers|lib/audio_cache.dart仅适用于 Android/iOS,我有条件地从 Dart 文件中排除以下导入:
import "package:audioplayers/audio_cache.dart"
Run Code Online (Sandbox Code Playgroud)
通过以下方式:
import "dart:math" if (dart.library.io) "package:audioplayers/audio_cache.dart";
Run Code Online (Sandbox Code Playgroud)
其中“dart:math”可以是任何 fake_stub Dart 文件。简而言之,这为Flutter 中的移动设备导入了一个库。详细信息在这里(感谢阿洛伊斯·丹尼尔!)。
在 Flutter-Web 实现中隐藏特定于平台的代码的最佳方法是什么?
import 'dart:io' show Platform;
bool isMobile() => Platform.isAndroid || Platform.isIOS;
class _MyPageState extends State<MyPage> {
dynamic _audioPlayer;
@override
void initState() {
if (isMobile()) {
_audioPlayer = AudioCache(prefix: 'sounds/');
_audioPlayer.load('mysound.mp3');
}
}
}
Run Code Online (Sandbox Code Playgroud)
AudioCache当然,这种幼稚的尝试在参考上失败了。
Error: Method not found: 'AudioCache'.
_audioPlayer = AudioCache(prefix: 'sounds/');
Run Code Online (Sandbox Code Playgroud) 我是 Flutter 的新手,正在使用 Flutter Web 应用程序,我的要求是创建和下载文本文件。像下面。
void getData() {
List<int> bytes = utf8.encode('this is the text file');
print(bytes); // Need to download this with txt file.
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我实现这一目标
我是 flutter 的初学者,我已经学会了当屏幕大小从桌面到平板电脑再到移动设备时如何处理大小和文本渲染。但我想了解当我在同一屏幕模式下减小屏幕尺寸时,如何更改尺寸或调整内容。
例如 -
return Container(
child: new Row(
children: <Widget>[
new Column(
children: <Widget>[new Text("Hello World")],
),
new Column(
children: <Widget>[
new Text(
"This is a long text this is a long test this is This is a long text this is a long test this is This is a long text this is a long test this is This is a long text this is a long test this is This is a long text this is …Run Code Online (Sandbox Code Playgroud) 当我在 flutter web 项目中添加一些像 ListView 这样的小部件时,我遇到了这个错误,我以前在使用 android 时从未遇到过这个错误
Exception has occurred.
"Error: Assertion failed: file:///D:/Android/flutter/packages/flutter/lib/src/rendering/mouse_tracking.dart:312:12
!_debugDuringDeviceUpdate
is not true
at Object.throw_ [as throw] (http://localhost:23584/dart_sdk.js:4328:11)
at Object.assertFailed (http://localhost:23584/dart_sdk.js:4275:15)
at mouse_tracking.MouseTracker.new.[_deviceUpdatePhase] (http://localhost:23584/packages/flutter/src/rendering/layer.dart.lib.js:4940:61)
at http://localhost:23584/packages/flutter/src/rendering/layer.dart.lib.js:4998:33
at mouse_tracking.MouseTracker.new.[_monitorMouseConnection] (http://localhost:23584/packages/flutter/src/rendering/layer.dart.lib.js:4935:7)
at mouse_tracking.MouseTracker.new.updateWithEvent (http://localhost:23584/packages/flutter/src/rendering/layer.dart.lib.js:4997:36)
at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:23584/packages/flutter/src/rendering/layer.dart.lib.js:5943:45)
at binding$5.WidgetsFlutterBinding.new.[_handlePointerEvent] (http://localhost:23584/packages/flutter/src/gestures/binding.dart.lib.js:257:14)
at binding$5.WidgetsFlutterBinding.new.[_flushPointerEventQueue] (http://localhost:23584/packages/flutter/src/gestures/binding.dart.lib.js:229:35)
at binding$5.WidgetsFlutterBinding.new.[_handlePointerDataPacket] (http://localhost:23584/packages/flutter/src/gestures/binding.dart.lib.js:213:65)
at Object._invoke1 (http://localhost:23584/dart_sdk.js:175453:7)
at _engine.EngineWindow.new.invokeOnPointerDataPacket (http://localhost:23584/dart_sdk.js:171307:15)
at _engine.PointerBinding.__.[_onPointerData] (http://localhost:23584/dart_sdk.js:158211:24)
at http://localhost:23584/dart_sdk.js:158585:26
at http://localhost:23584/dart_sdk.js:158557:16
at http://localhost:23584/dart_sdk.js:158310:11"
Run Code Online (Sandbox Code Playgroud)
我到处找,但没有任何线索,提前致谢
我的目标是在我的主页上的iframe的帮助下集成一个 flutter 小部件。主页不是用flutter写的。但是,我需要一个界面,通过该界面主页可以与小部件进行通信。所以我想到在主页上使用postMessage()并在 flutter widget 中使用html.window.addEventListener() 。现在我在 flutter 中收到一个事件,但看不到它的内容。我的临时解决方案是将消息保存在本地存储中,并仅使用侦听器作为通知程序,但我不太喜欢这种方法。有人对我的问题有更好的解决方案吗?
颤振测试小部件:
// ignore: avoid_web_libraries_in_flutter
import 'dart:html' as html;
import 'package:simple_cookies/simple_cookies.dart';
class MessageListener extends StatefulWidget {
@override
_MessageListenerState createState() => _MessageListenerState();
}
class _MessageListenerState extends State<MessageListener> {
String last;
@override
void initState() {
html.window.addEventListener('message', listen, true);
super.initState();
}
@override
void dispose() {
html.window.removeEventListener('message', listen, true);
super.dispose();
}
void listen(html.Event event) {
last = Cookies.get('iframe_message') ?? 'Error';
setState(() {});
}
@override
Widget build(BuildContext …Run Code Online (Sandbox Code Playgroud) 我知道有很多与此非常相似的问题;但他们的解决方案都不适合我。我都试过了。PS:我希望问题与我的index.html有关
问题:我正在使用 Firebase(在 Flutter Web 上),并且尝试通过它对用户进行身份验证。但是,在我尝试添加 Firebase 以使其正常工作后,我的网站甚至无法启动(黑屏)。我希望得到一些帮助来解决这个问题!
错误:未创建 Firebase 应用程序“[DEFAULT]” - 调用 Firebase App.initializeApp() (app/no-app)
注意:该问题出现在 Flutter web 上,但在我的 Android 手机上正常。另外,我花了几个小时查找所有类似问题的每个答案,但他们的解决方案都不起作用。另外,这是我第一次提问,如果我做错了什么,请告诉我。谢谢!
错误输出:
To hot restart changes while running, press "r" or "R".
For a more detailed help message, press "h". To quit, press "q".
FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp()
(app/no-app).
at Object.u [as app] (https://www.gstatic.com/firebasejs/8.4.3/firebase-app.js:1:18229)
at Object.app$ [as app]
(http://localhost:60058/packages/firebase_core_web/src/interop/core.dart.lib.js:42:101)
at new cloud_firestore_web.FirebaseFirestoreWeb.new
(http://localhost:60058/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:865:64)
at Function.registerWith
(http://localhost:60058/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:788:73)
at …Run Code Online (Sandbox Code Playgroud) 我不是在问 webview。这是关于 Flutter Web 应用程序。当用户按下浏览器内置的后退按钮时,我需要返回特定页面。
任何猜测?
当我按下后退按钮时出现此错误
Error: Assertion failed: org-dartlang-
sdk:///flutter_web_sdk/lib/_engine/engine/history.dart:110:14
_userProvidedRouteName != null
is not true
at Object.throw_ [as throw] (http://localhost:8300/dart_sdk.js:4770:11)
at Object.assertFailed (http://localhost:8300/dart_sdk.js:4721:15)
Run Code Online (Sandbox Code Playgroud) 我有独立的 Android 应用程序。然后我开发了较小的网络应用程序Flutter并将其导出到网络服务器。它WebView作为 Android 版 Kotlin 中该独立应用程序的一部分加载到内部。
Android 支持 postmessaging,我可以WebView通过渠道直接发送数据。我的问题是如何在 Flutter Dart 代码中(在我的 Web 应用程序中)收听这些消息?
这是我在 Kotlin Android App 中使用的代码:
private var port: WebMessagePort? = null
@TargetApi(Build.VERSION_CODES.M)
private fun initPostMessagePort(){
val channelsAvailable = webView.createWebMessageChannel()
port = channelsAvailable.firstOrNull()
port?.apply {
setWebMessageCallback(object : WebMessageCallback() {
override fun onMessage(port: WebMessagePort, message: WebMessage) {
//TODO do something with message
}
})
}?:kotlin.run {
App.log("Port initialization failed - channels not available")
}
}
@TargetApi(Build.VERSION_CODES.M)
private fun sendMessageToPort(message: String){
port?.let …Run Code Online (Sandbox Code Playgroud) 尝试在 Web 浏览器中运行 Flutter 应用程序时出现错误。
以下是我在运行应用程序时得到的输出:
Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
../../../.pub-cache/hosted/pub.dartlang.org/wav
e-0.1.0/lib/config.dart:46:13: Error: Method not found: 'throwNullError'.
throwNullError('custom', 'colors` or `gradients');
^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dartlang.org/wave-0.1.0/lib/config.dart:60:13: Error: Method not found: 'throwNullError'.
throwNullError('custom', 'durations');
^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dartlang.org/wave-0.1.0/lib/config.dart:66:13: Error: Method not found: 'throwNullError'.
throwNullError('custom', 'heightPercentages');
^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dartlang.org/flutter_platform_widgets-0.60.2/lib/src/platform_app_bar.dart:209:9: Error: No named parameter with the name 'actionsForegroundColor'.
actionsForegroundColor: data?.actionsForegroundColor,
^^^^^^^^^^^^^^^^^^^^^^
../../FlutterProjects/SDK/flutter/packages/flutter/lib/src/cupertino/nav_bar.dart:220:9: Context: Found this candidate, but the arguments don't match.
const CupertinoNavigationBar({
^^^^^^^^^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dartlang.org/flutter_platform_widgets-0.60.2/lib/src/platform_app_bar.dart:229:7: Error: No named …Run Code Online (Sandbox Code Playgroud) flutter-web ×10
flutter ×9
dart ×3
android ×1
firebase ×1
flutter-flex ×1
iframe ×1
import ×1
ios ×1
postmessage ×1
web ×1