Flutter应用程序可在android上运行,但无法在桌面上运行

时间:2019-05-21 19:43:23

标签: flutter

Flutter应用程序可在Android设备上正常运行,但在桌面上显示空白窗口。标题栏也不匹配。还通过Google代码实验室的示例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(从桌面运行)

1 个答案:

答案 0 :(得分:0)

字体丢失是因为应用程序正在使用您计算机上未安装的字体(很可能是Roboto,因为您使用Android作为平台替代),如您在the Fonts section of the desktop shells page中所链接到的问题。