小编duf*_*ffy的帖子

Flutter WillPopScope 与 AlertDialog 迁移到空安全

我最近将我的 Flutter 应用程序迁移到空安全,但 WillPopScope 与 AlertDialog 结合使用会导致问题。WillPopScope期望Future<bool>showDialog返回Future<bool?>,我不知道如何将一个投射到另一个上。

Widget _buildBody(BuildContext context) {
  return WillPopScope(
    onWillPop: (() => _onBackPressed(context)) as Future<bool> Function(),
    child: new Container([...]),
  );
}

// this should return a Future<bool> but showDialog doesn't allow that
Future<bool?> _onBackPressed(BuildContext context) async {
  if (someCondition) {
    // showDialog returns a Future<T?> 
    return showDialog(
      context: context,
      builder: (context) => new AlertDialog(
        [...]
        actions: <Widget>[
          new TextButton(
            child: Text("cancel",
            onPressed: () => Navigator.of(context).pop(false),
          ),
          new TextButton( …
Run Code Online (Sandbox Code Playgroud)

flutter dart-null-safety

8
推荐指数
2
解决办法
8454
查看次数

MVC:什么更好,每个数据库一个大型存储库或每个业务实体一个?

这次我有一个更哲学的问题.

大多数MVC教程/书籍似乎建议将一个存储库的范围限制为模型的一个方面,并设置多个存储库以涵盖所有模型类.(例如:ProjectRep,UserRep,ImageRep,最终都映射到同一个db.)

我可以看到这将如何使单元测试变得更简单但我无法想象这将如何在现实世界中起作用,在现实世界中大多数实体之间具有相互关系.最后,我总是发现自己每个数据库连接都有一个巨大的存储库类,并且用于单元测试的同样是一个笨拙的FakeRepository.

那么,你有什么看法?我应该更加努力地分离出存储库吗?是否ProductRep通过PurchaseHistory引用UserRep中的数据,反之亦然?当访问单个数据库时,不同的代表如何确保它们不会互相锁定?

谢谢,达菲

asp.net-mvc design-patterns

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

是什么导致了 Android Studio logcat 中的 E/BufferItemConsumer 错误消息?

在调试我的 android 应用程序时,Android Studio logcat 窗口在每次点击时都充斥着数十个相同的 BufferItemConsumer 错误。这与使用模拟器或物理设备无关。

08-13 18:15:44.497 6005-6005/org.xx.debug E/BufferItemConsumer: [unnamed-6005-129] Failed to release buffer: Unknown error -1 (1)
08-13 18:15:44.499 6005-6005/org.xx.debug E/BufferItemConsumer: [unnamed-6005-130] Failed to release buffer: Unknown error -1 (1)
08-13 18:15:44.502 6005-6005/org.xx.debug E/BufferItemConsumer: [unnamed-6005-131] Failed to release buffer: Unknown error -1 (1)
Run Code Online (Sandbox Code Playgroud)

AS 声称这些消息与应用程序相关,但日志中没有提供其他信息。谷歌搜索也没有任何结果。

知道我应该从哪里开始搜索以修复导致此问题的任何潜在错误或至少抑制消息吗?它们不仅令人讨厌,因为它们排除了任何有意义的日志消息。

android android-logcat

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

Flutter:在保持纵横比的同时缩小图像以适应行

我想并排显示两个图像,上面和下面都有一些文字。布局必须在纵向和横向模式下工作。这些图像是从网络加载的,我不知道它们的尺寸,尽管我知道纵横比 (3:4) 和方向(纵向)。

当前的解决方案在纵向模式下运行良好,但在横向模式下完全失败。这里有两张图片的中间部分被缩小以适应宽度,最终的图片对于可用空间来说太高了。

[...]
@override
Widget build(BuildContext context) {
  return Center(
    child: Column(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        Text('Text 1', style: Theme.of(context).textTheme.headline),
        IntrinsicHeight(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Expanded(
                child: TrimmedImage(left.src, () => _advanceRight()),
              ),
              Expanded(
                child: TrimmedImage(right.src, () => _advanceLeft()),
              ),
            ],
          ),
        ),
        Text('Text 2, possibly lines and lines and lines and lines and lines anlines and lines of stuff.',
          style: Theme.of(context).textTheme.title,
          textAlign: TextAlign.center,
        ),
      ],
    ),
  );
} 
[...]

class TrimmedImage extends …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-layout

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

在select语句中从IEnumerable转换为Queryable?

我有一个包含一堆访问函数的数据库存储库.我现在想要构建一个虚假的存储库,它为单元测试提供类似的功能.与真实存储库不同,这个使用简单列表而不是linqtosql生成的模型类.

大多数假存储库函数看起来与真实存储库函数完全相同,最后只需要额外的ToQueryable().但是,我现在有一个似乎需要更复杂的演员.

   public class FakeUserRepository : IUserRepository {
          public IQueryable<SelectListItem> GetRecords(int userid) {
                    // fake_table is a list
                    return (from a in fake_table select
                    new SelectListItem {
                        Value = a.ID.ToString(),
                        Text = a.Name
                    });
          }
    }
Run Code Online (Sandbox Code Playgroud)

目前,这给出了错误"无法隐式转换类型'System.Collections.Generic.IEnumerable.)我对错误消息并不感到惊讶,但我不知道如何修复转换.

c# model-view-controller unit-testing

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

在Angular 4中对图像交换进行动画处理(在AngularJS中为ng-animate-swap交换)

我想在angular 4应用中为图像交换设置动画。当控制器替换img src属性时,旧图像应消失并出现新图像。

在AngularJS中,可以通过使用ng-animate-swap更改不透明度来实现。但是,Angular 4似乎不支持动画交换。没有交换触发器如何实现?

我尝试为src属性添加从void到*的过渡,然后又添加回来,但这并没有按预期工作。第一个图像是有动画的,后来交换是在没有动画的情况下发生的。

@Component({
  selector: 'app-play-card',
  template: '<div (click)="loadImg()"><img [@fade]="imgsrc" src="{{ imgsrc }}" /></div>',
  styleUrls: ['./play-card.component.css'],
  animations: [
    trigger('fade', [
      transition('void => *', [
        style({opacity: 0.1}),
        animate(5000, style({opacity: 1}))
      ]),
      transition('* => void', [
        style({opacity: 0.9}),
        animate(5000, style({opacity: 0}))
      ])
    ])
  ]
})
Run Code Online (Sandbox Code Playgroud)

css animation web-animations angular angular-animations

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

使用自定义适配器时,ListView 不会使用主题设置样式

我有包含三个片段的 minidemo。一个显示两个TextView和一个editview直接,下一个使用自定义适配器将相同的布局视为列表中的行,第三个显示一个带有标准适配器的普通列表(simple_list_item_1)

活动使用标准主题(Theme.AppCompat.Light.DarkActionBar),我没有修改。

我本来希望所有三个块的样式都相似。相反,带有自定义适配器的第二个块似乎根本没有根据浅色主题进行样式设置。(见文末截图)

理想情况下,我希望自定义列表的行的样式类似于第一个块。或者,我想应用第三个块的样式。但是,所有字体和背景似乎都有些偏色,我不确定如何找出当前用作主题一部分的内容。因此,通过手动分配文本颜色、大小、背景等来修复中间块的样式不是一种选择。

整个演示请参考MiniDemo

这是 item_row.xml 布局文件(顶层相对布局标签好像被编辑器剥离了。完整布局请到gitlab

<TextView android:text="large"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:textAppearanceLarge"
    android:id="@+id/text1_field" />

<TextView android:text="large inverse"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/text2_field"
    android:textAppearance="?android:attr/textAppearanceLargeInverse"
    android:layout_centerHorizontal="true" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:ems="5"
    android:id="@+id/edit_field"
    android:layout_alignParentRight="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

自定义片段。同样,完整版在gitlab 上

public class CustomItemFragment extends ListFragment {
String[] DATA = new String[] {"foo1", "foo2", "foo3"};

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ItemAdapter adapter = new ItemAdapter(this.getActivity().getApplicationContext(), DATA);
    setListAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)

}`

适配器(gitlab):

public class …
Run Code Online (Sandbox Code Playgroud)

android listview android-appcompat android-arrayadapter android-theme

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

在flutter ios项目中干净构建后,XCode CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER标志不断重置

我正在为云构建(AppCenter)设置我的 flutter ios 应用程序,但我的 xcode 配置(?)遇到了问题。

在本地构建时,我曾经在 Xcode 中设置链接器标志以防止常见的“双引号包含”错误。(已知cocoapod问题,显然...)滴答在Xcode GUI设置标志CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO./ios/Runner.xcodeproj/project.pbxprojios/Pods/Pods.xcodeproj/project.pbxproj,并允许建立到结束,有很多的警告,但没有错误。

我提交了两个 pbxproject 文件(甚至整个 ios/Pods 目录),并认为这会保存我的标志设置,但我必须意识到从新结帐中构建会重新生成 Pods/ 配置,默认设置为 true。

我怎样才能让 Flutter ios 配置记住跨干净构建的标志设置?

PS:我应该提到我运行的是稍旧版本的 xcode (11.3.1)

xcode ios flutter

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