flutter - Flutter 应用程序可在 android 上运行,但在桌面上失败
问题描述
Flutter 应用程序在 android 设备上按预期工作,但在桌面上显示空窗口。标题栏也不匹配。也使用来自谷歌代码实验室的示例 hello world 进行了测试。
我已经覆盖了目标平台,如此处所述https://github.com/flutter/flutter/wiki/Desktop-shells。
颤振医生:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.6.0, on Linux, locale en_IN)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
[!] Android Studio (version 3.4)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] IntelliJ IDEA Community Edition (version 2019.1)
[✓] Connected device (1 available)
这很好,因为我正在使用物理设备或主机系统。Flutter 设备显示我的主机系统。构建和运行时没有错误(用详细检查)。
flutter run o/p: flutter run
Launching lib/main.dart on Linux in debug mode...
Building Linux application...
Flutter is taking longer than expected to report its views. Still trying...
Syncing files to device Linux...
4,551ms (!)
To hot reload changes while running, press "r". To hot restart (and rebuild
state), press "R".
An Observatory debugger and profiler on Linux is available at:
http://127.0.0.1:44463/x2_TrHddHQg=/
For a more detailed help message, press "h". To detach, press "d"; to quit,
press "q".
示例代码:
import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride;
import 'package:flutter/material.dart';
import 'dart:io' show Platform;
void main() {
TargetPlatform targetPlatform;
if (Platform.isMacOS) {
targetPlatform = TargetPlatform.iOS;
} else if (Platform.isLinux || Platform.isWindows) {
targetPlatform = TargetPlatform.android;
}
if (targetPlatform != null) {
debugDefaultTargetPlatformOverride = targetPlatform;
}
runApp(new FriendlychatApp());
}
class FriendlychatApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Friendlychat",
home: new ChatScreen(),
);
}
}
class ChatScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text("Friendlychat")),
body: Center(
child: Text('Hello World'),
),
);
}
}
预期:https ://imgur.com/0zZ8vI9 (来自android运行)
实际:https ://imgur.com/SVYUAaS (从桌面运行)
解决方案
字体丢失是因为应用程序使用的字体未安装在您的计算机上(很可能是 Roboto,因为您使用 Android 作为平台覆盖),如您在您的链接到的桌面外壳页面的字体部分中所述问题。
推荐阅读
- python-3.x - Pandas: I want to multiply two columns with 19 million rows, but system runs out of memory (Memory Error)
- prometheus - 如何在promql中的count_values之后过滤标签名称
- javascript - 在 AWS S3 SDK 中上传文件
- excel - 在不打开工作簿的情况下检查工作表密码是否受到保护
- blogger - 一些 Blogger 标签页面仅显示 4 篇文章,即使 20 篇文章具有该标签
- julia - @time in julia prints different time
- html - 使用flexbox时如何覆盖两个div?
- java - ImageIcon 的二维数组显示不一致且仅部分显示在 JPanel 中
- swift - 我可以使用 if 来比较包含参数的枚举吗?
- dart - Not showing icon app in Android 9.0 Flutter