If you want to make Flutter RaisedButton selected state? In order to give this Container a similar behavior to the press functionality of the RaisedButton, I wrapped it within a GestureDetector, and controlled the change of the state inside onTap call.
Here is example code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import 'package:flutter/material.dart'; void main() { runApp(new MaterialApp( home: new MyApp())); } class MyApp extends StatefulWidget { @override State<StatefulWidget> createState() { return new _MyAppState(); } } class _MyAppState extends State<MyApp> { Color _myColor = Colors.green; String _myAccountState = "Account Enabled"; @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text("Manage Accounts"), centerTitle: true, ), body: new Center( child: new GestureDetector( child: new Container( decoration: new BoxDecoration(color: Colors.grey), child: new Text( _myAccountState, style: new TextStyle(color: _myColor),), ), onTap: () { setState(() { if (_myColor == Colors.green) { _myAccountState = "Account Disabled"; _myColor = Colors.orange; } else { _myAccountState = "Account Enabled"; _myColor = Colors.green; } }); }, ) ), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.