【问题标题】:Is ElevatedButton working correctly for the web?ElevatedButton 在网络上是否正常工作?
【发布时间】:2021-05-12 18:59:55
【问题描述】:

我正在开发我的第一个 Flutter 项目,我的目标是让我的应用在所有平台(Android、iOS、Web)上运行。

当我使用 ElevatedButton 时,我的前额慢慢变得更红了。我无法让它在网络上运行。

这是它在 Android 中的样子:(正确)

这是它在网络上的样子:(不正确)

这是我的主题:

theme: ThemeData(
  elevatedButtonTheme: ElevatedButtonThemeData(
    style: ElevatedButton.styleFrom(
      primary: Colors.black,
      onPrimary: Colors.yellowAccent,
      side: BorderSide(width: 2.5, color: Colors.yellowAccent),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
      textStyle: TextStyle(
        fontSize: 15, fontWeight: FontWeight.w600
      ),
      elevation: 6,
      shadowColor: Colors.yellowAccent,
      padding:  EdgeInsets.all(8.0),
    ),
  ),
),

这是我的按钮:

Container(
  padding: EdgeInsets.all(8.0),
  child: ElevatedButton(
  child: Text("MY BUTTON"),
  onPressed: () => setState(() {
    _launched = _launchInBrowser('https://www.mywonderfulsite.com');
  }),
)),

这是 ElevatedButton 的“功能”还是可以使用它来解决?

欣赏建议。

【问题讨论】:

标签: flutter web button


【解决方案1】:

我找到的唯一解决方案是放置一个固定宽度和高度的容器。像这样的:

Container(
  width: 124.0,   // <-- Added this...
  height: 48.0,   // <--- ...and this.
  padding: EdgeInsets.all(8.0),
  child: ElevatedButton(
  child: Text("MY BUTTON"),
  onPressed: () => setState(() {
    _launched = _launchInBrowser('https://www.mywonderfulsite.com');
  }),
)),

希望它适用于所有平台和版本。我已经测试了最基本的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 2015-07-16
    • 2021-10-24
    相关资源
    最近更新 更多