小编Gwh*_*yyy的帖子

在 Flutter 中使用可变字体仅对每个 FontWeight 显示 FontWeight.w400 或 FontWeight.w600

我在尝试使用从 fonts.google.com 下载的任何可变字体时遇到问题

这是我得到的结果: 使用可变字体的结果

预期结果(使用多个固定字体文件获得): 使用多个文件的结果

这是使用的代码:

  • 页:
Scaffold(
  body: Center(
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: FontWeight.values
          .map(
            (weight) => Text(
              'This text has weight $weight',
              style: TextStyle(fontWeight: weight),
            ),
          )
          .toList(),
    ),
  ),
);
Run Code Online (Sandbox Code Playgroud)

应用程序:

MaterialApp(
  home: ...,
  theme: ThemeData(
    fontFamily: 'Sono',
  ),
)
Run Code Online (Sandbox Code Playgroud)

酒吧规格:

flutter:
  uses-material-design: true

  ...

  fonts:
    - family: Sono
      fonts:
        - asset: assets/fonts/Sono-VariableFont.ttf
Run Code Online (Sandbox Code Playgroud)

尝试了很多事情,比如将我的应用程序包装在 a 中DefaultTextStyle或更改fontVariations参数。对可变字体没有影响。

fonts flutter

13
推荐指数
1
解决办法
3492
查看次数

get.put 和 get.lazyput 之间的区别

我对 的依赖注入很陌生,所以有人可以向我解释和Getx的好处并告诉我它们有什么区别吗?Get.put()Get.lazyPut()

dart flutter flutter-getx

11
推荐指数
3
解决办法
2万
查看次数

我在 Mac 上运行 flutterfire 配置命令时遇到错误

Unhandled exception:
Exception: /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- xcodeproj (LoadError)
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from -e:1:in `<main>'

#0      ConfigCommand.run (package:flutterfire_cli/src/commands/config.dart:517:11)
<asynchronous suspension>
#1      CommandRunner.runCommand (package:args/command_runner.dart:209:13)
<asynchronous suspension>
#2      main (file:///Users/dylanguzman/.pub-cache/hosted/pub.dartlang.org/flutterfire_cli-0.2.6+1/bin/flutterfire.dart:57:5)
<asynchronous suspension>
Run Code Online (Sandbox Code Playgroud)

我试过 :

flutterfire configure --project=test-app-egr423
Run Code Online (Sandbox Code Playgroud)

使用以下 Firebase 应用成功生成 Firebase 配置文件 lib/firebase_options.dart:

dart firebase flutter

8
推荐指数
1
解决办法
1406
查看次数

处理 Flutter 应用程序中的 Activity 被破坏

当在Android开发者选项中打开“不要保留活动”时,Flutter应用程序的导航路线堆栈似乎被清除,并且Android应用程序像一个新的开始一样显示第一个屏幕。

在 Flutter Android 应用程序中保留或恢复导航路由堆栈的正确方法是什么?

navigation android dart back-stack flutter

7
推荐指数
1
解决办法
1153
查看次数

如何控制 SegmentedButton 小部件的选定和未选定背景颜色

我正在尝试新的SegmentedButton小部件:

SegmentedButton<int>(
  onSelectionChanged: (i) {},
  showSelectedIcon: false,
  style: ButtonStyle(
    backgroundColor: MaterialStatePropertyAll(Theme.of(context).primaryColor),
    iconColor: MaterialStateProperty.all(Colors.white),
  ),
  segments: const <ButtonSegment<int>>[
    ButtonSegment<int>(
      value: 12,
      icon: Icon(FlutterRemix.thumb_up_fill),
      enabled: true,
    ),
    ButtonSegment<int>(
      value: 20,
      icon: Icon(FlutterRemix.thumb_down_fill),
    ),
  ],
  selected: {12},
),
Run Code Online (Sandbox Code Playgroud)

此代码显示了两个分段按钮,如下所示:

分段按钮

当我设置时,如何自定义选定和未选定按钮的颜色:

backgroundColor: MaterialStatePropertyAll(Theme.of(context).primaryColor),
Run Code Online (Sandbox Code Playgroud)

它确实为选定的和选定的设置背景颜色。

谢谢你!

dart flutter

7
推荐指数
1
解决办法
3877
查看次数

无效参数:类型为 Api 的对象/工厂已在 GetIt 内注册

当我尝试在 iOS 模拟器上启动我的 flutter 应用程序时,我看到一个白色的空白屏幕,如下所示:

\n
 Launching lib/main.dart on iPhone 12 Pro Max in debug mode...\nRunning Xcode build...                                                  \n \xe2\x94\x94\xe2\x94\x80Compiling, linking and signing...                        13.7s\nXcode build done.                                           38.0s\n[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: Invalid argument(s): Object/factory with  type Api is already registered inside GetIt. \n#0      throwIf (package:get_it/get_it_impl.dart:7:18)\n#1      _GetItImplementation._register (package:get_it/get_it_impl.dart:729:5)\n#2      _GetItImplementation.registerLazySingleton (package:get_it/get_it_impl.dart:502:5)\n#3      setupLocator (package:r/locator.dart:14:18)\n#4      main (package:r/main.dart:12:3)\n#5      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:140:25)\n#6      _rootRun (dart:async/zone.dart:1354:13)\n#7      _CustomZone.run (dart:async/zone.dart:1258:19)\n#8      _runZoned (dart:async/zone.dart:1788:10)\n#9      runZonedGuarded (dart:async/zone.dart:1776:12)\n#10     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:133:5)\n#11     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)\n#12     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.<\xe2\x80\xa6>\nSyncing files to device iPhone 12 Pro Max...                       137ms\n
Run Code Online (Sandbox Code Playgroud)\n

xcode dart dart-pub flutter flutter-dependencies

5
推荐指数
1
解决办法
2186
查看次数

Flutter 本地通知在真实设备(Android)上不起作用

我正在使用 Flutter 构建 Android 应用程序。我的应用程序需要显示本地通知。我正在使用这个包,https://pub.dev/packages/flutter_local_notifications。当我在模拟器上显示通知时,它正在工作。但当我编译发布 APK 并将其安装在实际设备上时,它不起作用。

这是NotificationService类

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationService
{
  static FlutterLocalNotificationsPlugin? flip;

  static FlutterLocalNotificationsPlugin getFlipInstance()
  {
    if (flip == null) {
      flip = FlutterLocalNotificationsPlugin();

      // app_icon needs to be a added as a drawable
      // resource to the Android head project.
      var android = const AndroidInitializationSettings('@mipmap/ic_launcher');
      var ios = const IOSInitializationSettings();

      var settings = InitializationSettings(android: android, iOS: ios);
      flip!.initialize(settings);
    }

    return flip as FlutterLocalNotificationsPlugin;
  }


  static Future showNotification(String title, String body) async {
    var …
Run Code Online (Sandbox Code Playgroud)

android dart flutter flutter-local-notification

5
推荐指数
0
解决办法
1189
查看次数

Flutter GetX - 如何管理控制器删除?

我有一个带有GetX控制器的 Flutter 应用程序。该应用程序有 6 个屏幕,每个屏幕都有其GetxController.

屏幕 1 和 2 用于登录系统,而屏幕 3 至 6 用于应用程序内容。

登录后,用户可以在屏幕 3-4-5 之间前进和后退,但是当他到达屏幕 6 时,他只能转到屏幕 3,并且必须删除所有先前的堆栈(因此他无法返回)。

1st problem:如果我从 Screen 6 执行 a Get.offAll(() => const Screen3()),Screen3 的控制器将被删除,并且不再起作用。我的解决方法(不知道这个词是否存在!:D)通过标记Controller3为永久

Get.put(Controller3(), permanent: true)

但这里来了

2nd problem:如果用户按下logout按钮(仅出现在屏幕 3 中),这次我需要将其Controller3删除。这次,调用Get.offAll不会删除控制器,也不会调用Get.delete<Controller3>(),因为它说

“Controller3”已被标记为永久,SmartManagement 无权删除它。

我陷入这种境地,我真的不知道该怎么办

controller dart flutter flutter-getx

4
推荐指数
1
解决办法
2273
查看次数

在 Dart/Flutter 中创建给定长度的列表

如何创建给定长度的列表?我希望我的列表只包含 3 个变量,它不应该扩展。

如何在 Dart/Flutter 中做到这一点?

list maxlength dart flutter

4
推荐指数
2
解决办法
8414
查看次数

使用 SignalR 进行 Flutter 推送通知

我在 Flutter 应用程序上使用 SignalR 推送通知,效果很好。我从后端获取消息并使用 flutter_local_notifications 显示通知。问题是 SignalR 服务会在一段时间后关闭。如何让我的应用程序保持在后台运行?甚至重新启动?

这是我的代码:

import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:isolate_test/Model/UserMessageModel.dart';
import 'package:signalr_core/signalr_core.dart';
import 'EndPointService.dart';
import 'NotificationService.dart';

class SignalRProvider {
  static String appName = "NOTIFICATION";
  static String? userName = "";
  static String deviceName = "android_app";
  static List<UserMessageModel> messages = <UserMessageModel>[];

  HubConnection connection = HubConnectionBuilder()
      .withUrl(
          'my_url',
          HttpConnectionOptions(
            logging: (level, message) => print(message),
          ))
      .withAutomaticReconnect()
      .withHubProtocol(JsonHubProtocol())
      .build();
  Function(bool update)? onMessagesUpdateCallback;
  SignalRProvider({
    this.onMessagesUpdateCallback,
  });

  setUsername(String username) {
    userName = username;
  }

  Future initSignalR(BuildContext context) async …
Run Code Online (Sandbox Code Playgroud)

signalr dart flutter

3
推荐指数
1
解决办法
2616
查看次数