Flutter冲水吧/小吃吧造型

vlf7wbxs  于 2023-01-27  发布在  Flutter
关注(0)|答案(2)|浏览(143)

我在flutter中使用了众所周知的flushbar包来显示flushbar/snackbar。
https://pub.dev/documentation/flushbar/latest/
我展示了一个错误刷新条,其中包含一个很小的title、一个很大的message和一个action/main-button
问题是我的刷新条看起来不太好,因为title + message位于action/main-button旁边的一行中,这使得消息非常不可读,因为在多行中,刷新条的宽度非常大。是否有办法将titlemessage放置在action/main-button之上,以便标题和消息使用刷新条的全长,而刷新条的宽度较小?

我的flushbar-code自动柜员机:

Flushbar(
      duration: Duration(seconds: _getFlushbarDuration(message)),
      icon: Icon(FontAwesomeIcons.exclamationTriangle, color: Colors.red),
      title: 'ERREUR',
      isDismissible: true,
      dismissDirection: FlushbarDismissDirection.HORIZONTAL,
      message: message,
      backgroundColor: Colors.blueGrey[700],
      leftBarIndicatorColor: Colors.red,
      mainButton: FlatButton(
        onPressed: onPressMethod,
        child:
            Text('$buttonText', style: TextStyle(color: Colors.lightBlue[500])),
      ),
    ).show(this.context);
  • 此网站有助于了解使用小吃店的最佳实践:*

解剖结构下的选项卡操作中:
https://material.io/components/snackbars/#anatomy
如果动作很长,可以显示在第三行。

更新1:

我已经设法做了一些类似于我想要的东西,虽然冲洗杆的高度仍然很大。顶部有一整部分冲洗杆可以移除+这个解决方案看起来不是最漂亮的一个,代码方面:

Flushbar(
      duration: Duration(seconds: _getFlushbarDuration(message)),
      icon: Icon(FontAwesomeIcons.exclamationTriangle, color: Colors.red),
      messageText: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Text('ERREUR',
              style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
          Text('$message', style: TextStyle(color: Colors.lightBlue[50])),
          Container(
            alignment: Alignment.bottomRight,
            child: FlatButton(
              onPressed: onPressMethod,
              child: Text('$buttonText',
                  style: TextStyle(color: Colors.lightBlue[500])),
            ),
          ),
        ],
      ),
      padding: const EdgeInsets.only(top: 50, bottom: 10),
      isDismissible: true,
      dismissDirection: FlushbarDismissDirection.HORIZONTAL,
      backgroundColor: Colors.blueGrey[700],
      leftBarIndicatorColor: Colors.red,
    ).show(this.context);

更新2:

这看起来更好,但我现在不能得到图标的动画,因为我添加了一个带边距的容器到图标。仍然不满意我必须在messageText中制作小部件的事实。在默认的SnackBar()小部件中制作这个小部件是否更合适?

Flushbar(
      duration: Duration(seconds: _getFlushbarDuration(message)),
      icon: Container(
        margin: const EdgeInsets.only(bottom: 50),
        child: Icon(FontAwesomeIcons.exclamationTriangle, color: Colors.red),
      ),
      messageText: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Text('ERREUR',
              style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
          Text(
            '$message',
            style: TextStyle(color: Colors.lightBlue[50]),
            softWrap: true,
          ),
          Align(
            alignment: Alignment.centerRight,
            child: FlatButton(
              onPressed: onPressMethod,
              child: Text('$buttonText',
                  style: TextStyle(color: Colors.lightBlue[500])),
            ),
          ),
        ],
      ),
      isDismissible: true,
      dismissDirection: FlushbarDismissDirection.HORIZONTAL,
      backgroundColor: Colors.blueGrey[700],
      leftBarIndicatorColor: Colors.red,
    ).show(this.context);
cclgggtu

cclgggtu1#

flushbar已经停产了,我建议用ScaffoldMessenger来显示一个SnackBar,你可以关注这个guide来了解更多细节。
如果你想在你的SnackBar上有一个“Title”和“Message”,你可以在要显示的String上添加一个换行符\n

final snackBar = SnackBar(
  content: Text('Title \nMessage'),
  action: SnackBarAction(
    label: 'Undo',
    onPressed: () {
      // Some code to undo the change.
    },
  ),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);

mwg9r5ms

mwg9r5ms2#

您可以使用名为another_flushbar的软件包

样式冲洗杆示例

Flushbar(
      title: "Hey Ninja",
      titleColor: Colors.white,
      message: "Lorem Ipsum is simply dummy text of the printing and typesetting industry",
      flushbarPosition: FlushbarPosition.TOP,
      flushbarStyle: FlushbarStyle.FLOATING,
      reverseAnimationCurve: Curves.decelerate,
      forwardAnimationCurve: Curves.elasticOut,
      backgroundColor: Colors.red,
      boxShadows: [BoxShadow(color: Colors.blue[800], offset: Offset(0.0, 2.0), blurRadius: 3.0)],
      backgroundGradient: LinearGradient(colors: [Colors.blueGrey, Colors.black]),
      isDismissible: false,
      duration: Duration(seconds: 4),
      icon: Icon(
        Icons.check,
        color: Colors.greenAccent,
      ),
      mainButton: FlatButton(
        onPressed: () {},
        child: Text(
          "CLAP",
          style: TextStyle(color: Colors.amber),
        ),
      ),
      showProgressIndicator: true,
      progressIndicatorBackgroundColor: Colors.blueGrey,
      titleText: Text(
        "Hello Hero",
        style: TextStyle(
            fontWeight: FontWeight.bold, fontSize: 20.0, color: Colors.yellow[600], fontFamily: "ShadowsIntoLightTwo"),
      ),
      messageText: Text(
        "You killed that giant monster in the city. Congratulations!",
        style: TextStyle(fontSize: 18.0, color: Colors.green, fontFamily: "ShadowsIntoLightTwo"),
      ),
    );

相关问题