小编boe*_*edi的帖子

颤振:如何防止设备方向改变并强制纵向?

我想阻止我的应用程序更改其方向并强制布局坚持"肖像".

在main.dart中,我把:

void main(){
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]);
  runApp(new MyApp());
}
Run Code Online (Sandbox Code Playgroud)

但是当我使用Android模拟器旋转按钮时,布局"跟随"新的设备方向......

我该怎么解决这个问题?

谢谢

dart flutter

52
推荐指数
13
解决办法
2万
查看次数

颤动:如何强制重启应用程序(在生产模式下)?

生产模式中,有没有办法强制完全重启应用程序(我不是在讨论开发时的热重载!).

实际使用案例:

  • 在初始化过程中,应用程序检测到没有网络连接.缺乏网络连接可能阻止了正确的启动(例如加载外部资源,如JSON文件......).

  • 在最初的握手过程中,需要下载一些重要资源的新版本(更新类型).

在这两种用例中,我希望应用程序继续完全重启,而不是必须在ApplicationState级别构建复杂的逻辑.

非常感谢您的提示.

flutter

25
推荐指数
9
解决办法
9697
查看次数

颤动:倒置ClipOval

我是Flutter的新手,我正在尝试编写一个库,允许用户平移/缩放他们的个人资料图片.

为了使它具有视觉效果,我想用"倒置"ClipOval堆叠它们的图像,以显示边界.

到目前为止,这是我获得的结果:

在此输入图像描述

这显示了边界,但这不是用户友好的,我想"反转"ClipOval,使剪辑的中心"清晰",外部变灰(类似于蒙版).

有没有办法实现这个目标?

这是我到目前为止的代码(其中一部分来自flutter_zoomable_image):

import 'dart:ui' as ui;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

class ImagePanner extends StatefulWidget {
  ImagePanner(this.image, {Key key}) : super(key: key);

  /// The image to be panned
  final ImageProvider image;

  @override
  _ImagePannerState createState() => new _ImagePannerState();
}

class _ImagePannerState extends State<ImagePanner> {
  ImageStream _imageStream;
  ui.Image _image;
  double _zoom = 1.0;
  Offset _offset = Offset.zero;
  double _scale = 16.0;

  @override
  void didChangeDependencies() {
    _resolveImage();
    super.didChangeDependencies();
  }

  @override
  void reassemble() {
    _resolveImage();
    super.reassemble();
  } …
Run Code Online (Sandbox Code Playgroud)

flutter

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

Flutter:自定义字体

找到的解决方案:

使用 Android Studio 解决了这个问题!我使用 Android Studio 运行该应用程序,一切正常!看起来 VSCode 不能很好地处理自定义字体。因此,当有人需要添加自定义字体时,我建议使用 Android Studio

我正在尝试在我的应用程序中使用名为“Great Vibes”的 Google 字体。

这就是我所做的:

  • 我在根文件夹中创建了一个“fonts”目录
  • 我复制了该目录中的“GreatVibes-Regular.ttf”文件(从谷歌字体网站下载)
  • 我在 pubspec.yaml 中引用了它(见下文)
  • 当我想使用它时,我在一个 TextStyle 中引用了它

结果:未使用该字体。

fonts:
    - family: GreatVibes
      fonts:
        - asset: fonts/GreatVibes-Regular.ttf
          weight: 400


new Text('My New Font',
            style: new TextStyle(
              color: Colors.white,
              fontFamily: 'GreatVibes',
              fontSize: 16.0,
            )),
Run Code Online (Sandbox Code Playgroud)

没有报告错误。我还通过在线 YAML 解析器验证了 yaml 这是输出:

{
  "description": "My app", 
  "dependencies": {
    "http": "^0.11.3+16", 
    "shared_preferences": "^0.4.0", 
    "url_launcher": "^2.0.0", 
    "cupertino_icons": "^0.1.0", 
    "image_picker": "^0.4.1", 
    "flutter_facebook_login": "^1.0.3", 
    "flutter_localizations": {
      "sdk": "flutter"
    }, …
Run Code Online (Sandbox Code Playgroud)

flutter

6
推荐指数
2
解决办法
6899
查看次数

Flutter - 语义 - 解释

谁能给我一个关于 Flutter 上下文中语义概念(它实际上是什么,何时使用,更新......)的清晰解释(或链接)?

我用谷歌搜索了很多,但到目前为止还没有找到任何好的解释。

提前谢谢了,

semantics flutter

6
推荐指数
1
解决办法
4961
查看次数

Flutter - InheritedWidget - dispose

我想知道是否有人知道何时处理一个InheritedWidget?

这个问题的原因是我正在做一些实验,我使用的是InheritedWidget作为BLoC的提供者.此BLoC在InheritedWidget级别初始化,并使用StreamController.

由于建议关闭StreamController,我试图找到一个解决方案.

这是一段代码(仅用于实验的愚蠢代码)来说明问题:

///
/// ApplicationProvider
/// 
/// A provider of ApplicationBloc
/// 
class ApplicationProvider extends InheritedWidget {
  //
  // Initialization of the BLoC
  //
  final ApplicationBloc bloc = new ApplicationBloc();

  ApplicationProvider({Key key, Widget child}) : super(key: key, child: child);

  @override
  bool updateShouldNotify(_) => true;

  static ApplicationBloc of(BuildContext context, [bool redraw = true]) {
    return redraw ? (context.inheritFromWidgetOfExactType(ApplicationProvider) as ApplicationProvider).bloc
                  : (context.ancestorWidgetOfExactType(ApplicationProvider) as ApplicationProvider).bloc;
  }
}

//
// The BLoC
//   
class ApplicationBloc {

  int _counter;
  StreamController<int> _counterController = …
Run Code Online (Sandbox Code Playgroud)

flutter

6
推荐指数
1
解决办法
6196
查看次数

颤动:多语言应用程序 - 如何覆盖语言环境?

我按照官方Flutter页面(见这里)中的解释,使我的应用程序以不同的语言工作.

根据文档,它检索用户的语言环境,这很好.

现在让我们假设我的应用程序支持不同的语言(例如EN,FR,ES,...),并且用户可以选择其中一种语言来使用该应用程序(所选语言将不同于在手机的设置),我该怎么做到这一点?

我如何强制应用程序区域设置并动态"重新加载"所有翻译?

Flutter页面没有解释这一点,我在文档中没有看到任何帮助我的东西......

这是当前的实现:

class Translations {
  Translations(this.locale);

  final Locale locale;

  static Translations of(BuildContext context){
    return Localizations.of<Translations>(context, Translations);
  }

  static Map<String, Map<String, String>> _localizedValues = {
    'en': {
      'title': 'Hello',
    },
    'fr': {
      'title': 'Bonjour',
    },
    'es': {
      'title': 'Hola',
    }
  };

  String text(String key){
    return _localizedValues[locale.languageCode][key] ?? '** ${key} not found';
  }
}

class TranslationsDelegate extends LocalizationsDelegate<Translations> {
  const TranslationsDelegate();

  @override
  bool isSupported(Locale locale) => ['en', 'fr','es'].contains(locale.languageCode);

  @override
  Future<Translations> load(Locale locale) {
    return …
Run Code Online (Sandbox Code Playgroud)

flutter

5
推荐指数
3
解决办法
5108
查看次数

Flutter:VSCode快捷方式具有@override列表

使用VSCode,是否有快捷方式(或任何其他方式)来获取所有Flutter @override方法的列表?

visual-studio-code flutter

5
推荐指数
2
解决办法
2238
查看次数

颤振:是否可以检测抽屉何时打开?

是否可以检测到抽屉何时打开,以便我们可以运行一些例程来更新其内容?

我的典型用例是显示关注者,喜欢者的数量……为此,我需要轮询服务器以获取此信息,然后进行显示。

我尝试实现NavigatorObserver来捕捉使抽屉可见/隐藏但NavigatorObserver没有检测到有关抽屉的任何事件。

这是链接到NavigatorObserver的代码:

import 'package:flutter/material.dart';

typedef void OnObservation(Route<dynamic> route, Route<dynamic> previousRoute);
typedef void OnStartGesture();

class NavigationObserver extends NavigatorObserver {
  OnObservation onPushed;
  OnObservation onPopped;
  OnObservation onRemoved;
  OnObservation onReplaced;
  OnStartGesture onStartGesture;

  @override
  void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
    if (onPushed != null) {
      onPushed(route, previousRoute);
    }
  }

  @override
  void didPop(Route<dynamic> route, Route<dynamic> previousRoute) {
    if (onPopped != null) {
      onPopped(route, previousRoute);
    }
  }

  @override
  void didRemove(Route<dynamic> route, Route<dynamic> previousRoute) {
    if (onRemoved != null)
      onRemoved(route, previousRoute);
  }

  @override
  void didReplace({ Route<dynamic> …
Run Code Online (Sandbox Code Playgroud)

flutter

4
推荐指数
5
解决办法
3719
查看次数

颤动:有2个FloatingActionButton时出现异常

在第一次构建页面时收到异常,此构建涉及2个FloatingActionButton.

但是,如果我注释掉2个FloatingActionButton中的一个,运行应用程序,在稍后阶段,我取消注释并继续进行热重新加载,它可以工作.

下面的代码实现了一个图像选择器,并为用户提供了从图库或摄像头中进行选择的选择.

有人看看这个,告诉我我做错了什么?

我突出显示了导致异常的代码部分.

这是代码:

class ProfilePage extends StatefulWidget {
  ProfilePage(this.profileId);
  final int profileId;
  @override
  _ProfilePageState createState() => new _ProfilePageState();
}

class _ProfilePageState extends State<ProfilePage> {
  var _imageInfo;

  @override
  void initState() {
    _imageInfo = mid.currentProfile['Photo'];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(Translations
            .of(context)
            .text(widget.profileId == -1 ? 'profiles_add' : 'profiles_edit')),
        actions: <Widget>[
          new IconButton(
            icon: new Icon(Icons.close),
            onPressed: () => Navigator.of(context).pop(null),
          ),
        ],
        leading: new Container(),
      ),
      body: …
Run Code Online (Sandbox Code Playgroud)

exception flutter

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

颤振:垃圾收集 - 如何检查?

在Flutter中,我如何检查是否正确释放(处置)所有内容?

我正在构建一个应用程序,我觉得模拟器在一系列热重载之后变慢了.

非常感谢你的回答.

flutter

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

Flutter:HttpClient post contentLength -- 异常

很奇怪...

为了将一些 JSON 数据发布到我的服务器,我将 contentLength 定义为 JSON 编码数据的长度,但随后我收到一个异常,提示“内容大小超过指定的 contentLength ”。相差1字节。

这是源代码:

Future<Map> ajaxPost(String serviceName, Map data) async {
  var responseBody = json.decode('{"data": "", "status": "NOK"}');
  try {
    var httpClient = new HttpClient();
    var uri = mid.serverHttps ? new Uri.https(mid.serverUrl, _serverApi + serviceName)
                              : new Uri.http(mid.serverUrl, _serverApi + serviceName);
    var request = await httpClient.postUrl(uri);
    var body = json.encode(data);

    request.headers
      ..add('X-mobile-uuid', await _getDeviceIdentity())
      ..add('X-mobile-token', await mid.getMobileToken());

    request.headers.contentLength = body.length;
    request.headers.set('Content-Type', 'application/json; charset=utf-8');
    request.write(body);

    var response = await request.close();
    if (response.statusCode == …
Run Code Online (Sandbox Code Playgroud)

flutter

2
推荐指数
1
解决办法
8888
查看次数

扑:ListTile如何适应页边距和标题/字幕样式?

我正在构建一个由各种小部件组成的表单,我想将它们全部对齐。

在下面的示例中,我正在使用TextFormField,ListTile等。

该问题与TextFormField>装饰>图标和ListTile>前导的对齐有关。

如您所见,ListTile>前导绝对不与TextFormField>装饰>图标对齐。

在文档中,我找不到有关如何调整ListTile>前导“左边距”的任何解释

子问题:如何设置ListTile标题和副标题的样式,使其看起来像TextFormField?

任何帮助都超过了欢迎。

源代码摘录:

_buildBody() {
    return new SafeArea(
      top: false,
      bottom: false,
      child: new Form(
        key: _formKey,
        autovalidate: false,
        child: new SingleChildScrollView(
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          child: new Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              /* -- Profile Picture -- */
              const SizedBox(height: 24.0),
              _buildProfilePicture(),

              /* -- Alias -- */
              new TextFormField(
                decoration: const InputDecoration(
                  border: const UnderlineInputBorder(),
                  filled: true,
                  icon: const Icon(Icons.person),
                  hintText: 'Enter an alias',
                  labelText: 'Alias *',
                ),
                onSaved: (String value) {
                  profile.alias …
Run Code Online (Sandbox Code Playgroud)

flutter

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

标签 统计

flutter ×13

dart ×1

exception ×1

semantics ×1

visual-studio-code ×1