如何在flutter中更改textField的下划线颜色?

时间:2018-07-17 05:35:19

标签: flutter flutter-layout

我试图定义Input装饰来更改输入TextField下划线的颜色。但这不起作用。有人可以建议我在这里错过什么吗?

这是代码段:

Dim deleg As New ValidationCallBack(AddressOf ValidationCallBackEvent)

Dim processor = New Processor(True)
Dim sXsdPathUri As String = "c:\temp\the.xsd"
Dim sXmlPathUri As String = "c:\temp\the.xml"

processor.SetProperty("http://saxon.sf.net/feature/timing", "true")
processor.SetProperty("http://saxon.sf.net/feature/validation-warnings", "false") 

Dim manager As SchemaManager = processor.SchemaManager     
Dim schemaUri As System.Uri
schemaUri = New System.Uri(sXsdPathUri)

manager.Compile(schemaUri)

Dim validator As SchemaValidator = manager.NewSchemaValidator
Dim settings As System.Xml.XmlReaderSettings = New System.Xml.XmlReaderSettings
settings.DtdProcessing = System.Xml.DtdProcessing.Ignore
Dim inputFileName As String = New Uri(sXmlPathUri).ToString()
Dim xmlReader As System.Xml.XmlReader = System.Xml.XmlReader.Create(inputFileName, settings)
validator.SetSource(xmlReader)

validator.SetInvalidityHandler(IIH)  'suss; but it needs a Saxon.Api.IInvalidityHandler..
validator.Run()
Try
    validator.Run()
    sResult = "Valid!!"
Catch ex As Exception
    Dim err As StaticError
    For Each err In validator.ErrorList 'still goes here

6 个答案:

答案 0 :(得分:4)

decoration: InputDecoration(
hintText: 'Username',
hintStyle: TextStyle(color: Colors.white),
enabledBorder: new UnderlineInputBorder(
                                borderSide: BorderSide(color: Colors.white, 
                                  width: 1.0, style: BorderStyle.none ),
),

只需将“ border”更改为“ enabledBorder”即可。希望有帮助!

答案 1 :(得分:4)

我们必须同时使用enabledBorderfocusedBorder

  • enabledBorder:当TextField没有重点时它将起作用。
  • focusedBorder:当TextField成为焦点时,它将起作用。
enabledBorder: new UnderlineInputBorder(
  borderSide: BorderSide(
    color: Colors.black
  ),
),
// and:
focusedBorder: new UnderlineInputBorder(
  borderSide: BorderSide(
    color: Colors.black
  ),
),

答案 2 :(得分:2)

刚刚使用-:

decoration: InputDecoration(        
  focusedBorder: UnderlineInputBorder(      
    borderSide: BorderSide(color: Colors.cyan),   
  ),    
),

对我有用:)

答案 3 :(得分:1)

您必须将小部件层次结构放在 MaterialApp 下。

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        title: 'Flutter WebView Demo',
        theme: new ThemeData(
          primarySwatch: Colors.blue,
        ),
          home: new Container(
             **//put widget here.**
        ));
  }
}

答案 4 :(得分:1)

您可以将TextField包裹在Theme中,然后像这样更改accentColor

Theme(
  data: Theme.of(context).copyWith(accentColor: Colors.red),
  child: TextField(),
)

答案 5 :(得分:0)

 child: TextField(

                  controller: email,
                  enabled: true,
                  keyboardType: TextInputType.emailAddress,
                  decoration: InputDecoration(

                    filled: true,
                    fillColor: Color(0xFFF2F2F2),
                    enabledBorder: new OutlineInputBorder(
                        borderSide: new BorderSide(color: Colors.orange)),
                    focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.orange),

                    ),
                    hintText: ' Email ',

                    icon: Icon(
                      Icons.email,
                      color: Colors.orange,
                      size: 30.0,
                    ),


                  )

                )
相关问题