Advertisement
Guest User

Untitled

a guest
Mar 28th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.93 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. class Home extends StatelessWidget {
  4.   @override
  5.   Widget build(BuildContext context) {
  6.     return Center(
  7.         child: Container(
  8.       padding: EdgeInsets.all(10.0),
  9.       child: Column(
  10.         mainAxisAlignment: MainAxisAlignment.center,
  11.         children: <Widget>[
  12.           Container(
  13.               padding: EdgeInsets.all(10.0),
  14.               child: Row(
  15.                 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  16.                 children: <Widget>[
  17.                   MyButton(color: Colors.blue, wasPressed: false),
  18.                   MyButton(color: Colors.blue, wasPressed: false),
  19.                   MyButton(color: Colors.blue, wasPressed: false),
  20.                 ],
  21.               )),
  22.           Container(
  23.               padding: EdgeInsets.all(10.0),
  24.               child: Row(
  25.                 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  26.                 children: <Widget>[
  27.                   MyButton(color: Colors.blue, wasPressed: false),
  28.                   MyButton(color: Colors.blue, wasPressed: false),
  29.                   MyButton(color: Colors.blue, wasPressed: false),
  30.                 ],
  31.               )),
  32.         ],
  33.       ),
  34.     ));
  35.   }
  36. }
  37.  
  38. class MyButton extends StatefulWidget {
  39.   MyButton({this.color, this.wasPressed});
  40.  
  41.   final Color color;
  42.   final bool wasPressed;
  43.  
  44.   @override
  45.   MyButtonState createState() => MyButtonState();
  46. }
  47.  
  48. class MyButtonState extends State<MyButton> {
  49.   bool pressed;
  50.   @override
  51.   void initState() {
  52.     super.initState();
  53.  
  54.     pressed = widget.wasPressed;
  55.   }
  56.  
  57.   @override
  58.   Widget build(BuildContext context) {
  59.     return RaisedButton(
  60.       color: pressed == true ? widget.color : Colors.amber,
  61.       onPressed: () {
  62.         setState(() {
  63.           pressed = !pressed;
  64.         });
  65.       },
  66.     );
  67.   }
  68. }
  69.  
  70. void main() => runApp(MaterialApp(
  71.       home: Scaffold(
  72.         body: Home(),
  73.       ),
  74.     ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement