如何全局更改边框颜色和OutlineButton的宽度?

我需要更改"C:/elasticsearch-7.3.0/driver/com.mysql.jdbc_5.1.5.jar" 的边框颜色宽度,我知道一种直接通过内联方式提及它的方法,如下所示:

OutlineButton

如果我按照以下所述进行操作,则它会影响OutlineButton( child: Text('SIGN IN'),padding: EdgeInsets.all(8.0),onpressed: handleSignIn,borderSide: BorderSide( color: Colors.white,//Color of the border style: BorderStyle.solid,//Style of the border width: 1,//width of the border ),) flatButton,而不会影响RaisedButton

OutlineButton

那么,如何仅在全球范围内(通过整个应用程序)更改MaterialApp( title: 'MyApp',theme: ThemeData( buttonTheme: ButtonThemeData( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(20),// this effects to flatButton and RaisedButton side: BorderSide( color: Colors.white,//Color of the border style: BorderStyle.solid,//Style of the border width: 1,//width of the border ),),); 的边框颜色宽度

hy5_hy5 回答:如何全局更改边框颜色和OutlineButton的宽度?

我认为您不能在OutlineButton中做到这一点。因此,我建议您在全局文件中创建全局主题数据。

var borderData=BorderSide(
    color: Colors.white,//Color of the border
    style: BorderStyle.solid,//Style of the border
    width: 1,//width of the border
  )

然后,您只需导入该全局文件即可轻松地在任何类中使用它。

OutlineButton(
  child: Text('SIGN IN'),padding: EdgeInsets.all(8.0),onPressed: handleSignIn,borderSide: borderData,)

这样可以减少您的样板代码。

,

除非将borderSide显式添加到OutlineButton,否则它将默认为1.0的宽度,solid的样式和此颜色:

Theme.of(context).colorScheme.onSurface.withOpacity(0.12)

您可以选择更改应用主题的onSurface,但这也会影响其他小部件。

您可以按照杰伊在其他答案中建议的方式进行操作,但是我更喜欢创建其他小部件。这样,如果您将来想对所有OutlineButton进行其他更改,则只需要更改自定义小部件即可:

import 'package:flutter/material.dart';

class OutlineButton2 extends OutlineButton {
  const OutlineButton2({
    Key key,@required VoidCallback onPressed,Widget child,}) : super(
    key: key,onPressed: onPressed,child: child,borderSide: const BorderSide(
      color: Colors.white,style: BorderStyle.solid,width: 1,),);
}
,

尝试删除OutlineButton

尝试以下代码:

 GestureDetector(
                  child: Container(
                    padding: EdgeInsets.all(8.0),decoration: BoxDecoration(
                      border: Border(
                          top: BorderSide(
                              width: 2.0,color: Theme.of(context).primaryColor)),child: Text('SIGN IN'),onTap: onPressed,

基本上GestureDetector将采用onPressed逻辑代码,而container将按照您的要求进行修饰,并在其中插入Text

,

该类已弃用,请改用 OutlinedButton

OutlinedButton(
      style: TextButton.styleFrom(
        primary: primaryColor,side: BorderSide(color: primaryColor),minimumSize: Size(200,50),
本文链接:https://www.f2er.com/3152657.html

大家都在问