您好,我有以下 Dart 代码,我希望CupertinoButton为橙色,但无论我做什么,都保持灰色。我尝试将其更改为其他颜色,但仍然保持灰色。
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/cupertino.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays([]);
return new MediaQuery(
data: new MediaQueryData(),
child: new Container(
decoration: new BoxDecoration(color: Colors.blue),
child: new Directionality(
textDirection: TextDirection.ltr,
child: new Scaffold(
body: new Column(
children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new CupertinoButton (
color: Colors.orange,
borderRadius: new BorderRadius.circular(30.0),
child:
new Text("Get Started",
textAlign: TextAlign.center,
style: new TextStyle(color: Colors.white),
),
)
],
),
],
)
)
)
)
);
}
}
最佳答案
根据documentation。如果您不提供onPressed回调功能,则该按钮将被禁用。
要启用它,您可以传递一个空函数,如下所示。
new CupertinoButton (
onPressed: ()=>{},
color: Colors.orange,
borderRadius: new BorderRadius.circular(30.0),
child:
new Text("Get Started",
textAlign: TextAlign.center,
style: new TextStyle(color: Colors.white),
),
)
关于dart - Flutter CupertinoButton颜色始终为灰色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50055637/