Reputation: 11
Hello I have the following dart code and I want the CupertinoButton to be orange but no matter what I do it stays grey. I have tried changing it to a different color and it still stays grey.
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),
),
)
],
),
],
)
)
)
)
);
}
}
Upvotes: 1
Views: 7981
Reputation: 579
Yes, you need to set onPressed:
to a valid value. Without it, your button is disabled, per the docs. My IDE actually throws an error without it.
Also, onPressed: ()=>{}
doesn't work for me, but onPressed: null
does to disable the CupertinoButton manually. So for my app, I set onPressed
to null if validation fails with a ternary.
Example:
onPressed: ()=> $myBoolVarTrue ? _myFunction() : null
Upvotes: 0
Reputation: 15789
According to the documentation. If you don't provide the onPressed a call back function, the button will be disabled.
To make it enable you can pass a empty function like this.
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),
),
)
Upvotes: 6