小编Kon*_*tin的帖子

Dart 对几种类型的通用约束并设置默认值

为了方便起见,我想为 RxDart 类制作一些扩展类。但是我找不到用泛型做一些基本事情的方法,例如我需要将泛型类型限制为几种类型。这是我将如何在 C# 中实现它

MyGenericType<T> where T : bool, int { ... }
Run Code Online (Sandbox Code Playgroud)

因此将 T 限制为 bool 和 int 类型。我将如何在飞镖中做同样的事情?文档仅显示具有单一类型限制的示例,如下所示:

class MyGeneric<T extends SomeClass> ...
Run Code Online (Sandbox Code Playgroud)

我也尝试使用逗号,但它做了另一件事,它需要我的泛型类型来扩展它们,这不是我需要的。有可能吗?

另一个相关问题:我还需要为这些泛型设置默认值。同样,C# 等价物将是

T value = default(T);
Run Code Online (Sandbox Code Playgroud)

飞镖中有这样的东西吗?

generics default extend dart

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

扑。如何使子部件超越其父部件?

我需要制作一个底部栏“购物车”图标并显示它拥有的许多商品。问题是我无法将数字标签放置得足够高。它被它的父约束所剪裁。截图证明了这一点

\n\n

在此输入图像描述

\n\n

按钮本身是一个 Column 小部件,其顶部有 Frare 动画“波浪”演员,其下方有一个堆栈(绿线下方)\n如果将标签向上移动,我会得到以下结果:

\n\n

在此输入图像描述

\n\n

标签本身被剪掉,波浪不知何故消失了。\n我尝试将堆栈包装在 LimitedBox、OverflowBox、SizedBox 中,但都没有解决问题。

\n\n

这是我想要的(理想情况下):

\n\n

在此输入图像描述

\n\n

让父级保留其原始位置和大小,但显示部分超出其的子级

\n\n

以下是按钮类的完整代码(计数器是在 _getCounter() 方法中创建的):

\n\n
class BottomBarButton extends StatefulWidget {\n\n  BottomBarMenuItemModel itemModel;\n  final double barHeight;\n\n\n  BottomBarButton(this.itemModel, this.barHeight);\n\n  @override\n  _BottomBarButtonState createState() => _BottomBarButtonState();\n}\n\nclass _BottomBarButtonState extends State<BottomBarButton> with SingleTickerProviderStateMixin {\n\n  AnimationController _scaleController;\n  Animation<double> _scaleTween;\n  Animation<Color> _colorTween;\n  Animation<Color> _reversedColorTween;\n  StreamSubscription<String> _streamSubscription;\n  StreamSubscription<String> _counterSubscription;\n  String _inactiveAnimation = \'idle\';\n\n  @override\n  void initState() {\n    _streamSubscription = Dispatch().onChangeBottomBar.stream.listen((menuId) {\n      if (widget.itemModel.id == menuId) {\n        return;\n      }\n      setState(() {});\n    });\n\n …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-layout

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

Flutter 使用内部动画为两条路线设置动画

我完全被它困住了。我想创建一个自定义页面路由,该路由将为 IN 和 OUT 页​​面设置动画。路线本身的动画是一项简单的任务,我这样做:

    import 'package:flutter/material.dart';

    class FromMenuRoute extends PageRouteBuilder {

      final Widget nextPage;
      final Widget prevPage;

      FromMenuRoute({this.prevPage, this.nextPage}) : super(
        transitionDuration: Duration(milliseconds: 500),
        pageBuilder: (
          BuildContext context,
          Animation<double> animation,
          Animation<double> secondaryAnimation,
        ) {
          return nextPage;
        },
        maintainState: false,
        transitionsBuilder: (
          BuildContext context,
          Animation<double> animation,
          Animation<double> secondaryAnimation,
          Widget child,
        ) {
          var colorTheme = CustomThemeData.of(context).colorTheme;
          return Material(
            child: Stack(
              overflow: Overflow.visible,
              children: <Widget>[
                SlideTransition(
                  position: Tween<Offset>(
                    begin: const Offset(0.0, 0.0),
                    end: const Offset(-0.3, 0.0),
                  ).animate(animation),
                  child: prevPage,
                ),
                SlideTransition( …
Run Code Online (Sandbox Code Playgroud)

animation routes flutter page-transition

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

扑。如何使容器比屏幕更宽?

我正在尝试为页面控制器创建视差背景。为此目的,我需要创建一个比屏幕宽的背景图像。我把它放在一个这样的容器里:

@override
  Widget build(BuildContext context) {

    return Material(
      child: Stack(
        children: [
          Container(
              width: 4000,
              height:  250,
              decoration: BoxDecoration(
                  image: DecorationImage(
                      image: AssetImage('assets/images/pizza_bg.png'),
                      fit: BoxFit.cover,
                      repeat: ImageRepeat.noRepeat
                  )
              )
          ),
        ],
      ),
    );
  }
Run Code Online (Sandbox Code Playgroud)

但问题是,无论我指定什么宽度,容器(当然还有图像)永远不会比屏幕更宽。有可能吗?ps 我尝试使用 SizedBox 和 AspectRatio 小部件,它们都给出了相同的结果

flutter flutter-layout

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

Xamarin.Forms FontAwesome 不适用于绑定属性

我想在我的 Xamarin.Forms 项目中添加很棒的字体,我已经将它添加到了项目中。然后我将 FontFamily 添加到这样的标签中:

<ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid Padding="15">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="9*" />
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Text="&#xf11a;" FontSize="20">

                                <Label.FontFamily>
                                    <OnPlatform x:TypeArguments="x:String">
                                        <On Platform="iOS" Value="Font Awesome 5 Free" />
                                        <On Platform="Android" Value="fa-regular-400.ttf#Font Awesome 5 Free Regular" />
                                    </OnPlatform>
                                </Label.FontFamily>

                            </Label>
                            <Label Grid.Column="1" Text="{Binding Title}" FontSize="20"/>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常,这是结果 在此处输入图片说明

但是当我将这些硬编码的东西更改为这样的可绑定属性时:

<Label Grid.Column="0" Text="{Binding FontAwesomeIconText}" FontSize="20">
Run Code Online (Sandbox Code Playgroud)

并在 c# 中这样设置

menuItems = new List<DrawerMenuItem>
            {
                new DrawerMenuItem {Id = MenuItemType.Browse, Title="Browse", FontAwesomeIconText = "&#xf11a;" },
                new DrawerMenuItem {Id …
Run Code Online (Sandbox Code Playgroud)

c# xamarin.forms.listview font-awesome-5

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

简单的正则表达式匹配它不应该匹配的内容

我正在编写一个文本格式化程序,需要清除中文拼音中的特殊字符并将其替换为拉丁字母。但我突然偶然发现了这个问题\n所以,假设我有这个音节

\n
shu\n
Run Code Online (Sandbox Code Playgroud)\n

我需要检查它是否包含以下列表中的一个字母:

\n
\xc3\xbc\xc7\x96\xc7\x98\xc7\x9au\xcc\x88\xcc\x8cu\xcc\x88\xcc\x86\xc7\x9c\n
Run Code Online (Sandbox Code Playgroud)\n

我有一个像这样的正则表达式\n[\xc3\xbc\xc7\x96\xc7\x98\xc7\x9au\xcc\x88\xcc\x8cu\xcc\x88\xcc\x86\xc7\x9c]{1}

\n

它不应该匹配简单的“u”,但它确实匹配。

\n

在此输入图像描述

\n

我该如何解决这个问题?

\n

regex

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