Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1.  
  2. enum ColorState { YELLOW, BLUE }
  3. enum BrightState { B100, B80 }
  4.  
  5. class HomePage extends StatefulWidget {
  6. @override
  7. _HomePageState createState() => _HomePageState();
  8. }
  9.  
  10. class _HomePageState extends State<HomePage> {
  11. var color = ColorState.YELLOW;
  12. var bright = BrightState.B100;
  13. bool switchOnOf = true;
  14.  
  15. void changeColor() {
  16. if (color == ColorState.YELLOW) {
  17. setState(() {
  18. color = ColorState.BLUE;
  19. });
  20. } else {
  21. setState(() {
  22. color = ColorState.YELLOW;
  23. });
  24. }
  25. }
  26.  
  27. void changeBright() {
  28. if (bright == BrightState.B100) {
  29. setState(() {
  30. bright = BrightState.B80;
  31. });
  32. } else {
  33. setState(() {
  34. bright = BrightState.B100;
  35. });
  36. }
  37. }
  38.  
  39. void changeSwitch() {
  40. setState(() {
  41. switchOnOf = !switchOnOf;
  42. });
  43. }
  44.  
  45. @override
  46. Widget build(BuildContext context) {
  47. return Scaffold(
  48. body: Column(
  49. crossAxisAlignment: CrossAxisAlignment.start,
  50. children: <Widget>[
  51. latern(),
  52. title(),
  53. SwitchButton(
  54. changeColor: changeColor,
  55. changeBright: changeBright,
  56. changeSwitch: changeSwitch,
  57. brightState: bright,
  58. colorState: color,
  59. onOffState: switchOnOf,
  60. )
  61. ],
  62. ),
  63. );
  64. }
  65.  
  66. Widget latern() {
  67. return Stack(
  68. children: <Widget>[
  69. //lantern background
  70. Container(
  71. height: Sizes.height(context) * 0.6,
  72. decoration: BoxDecoration(
  73. color: ColorPalette.blueGradientBottom.withOpacity(0.4),
  74. borderRadius: BorderRadius.only(
  75. bottomRight: Radius.circular(Sizes.width(context)),
  76. bottomLeft: Radius.circular(Sizes.width(context)),
  77. )
  78. ),
  79. ),
  80. Lamp(
  81. colorState: color,
  82. brightState: bright,
  83. onOffState: switchOnOf,
  84. ),
  85. ],
  86. );
  87. }
  88.  
  89. Widget title() {
  90. return Padding(
  91. padding: const EdgeInsets.all(26.0),
  92. child: Text(
  93. 'Round Lanterns \nLamp',
  94. style: TextStyle(
  95. fontWeight: FontWeight.w600,
  96. fontSize: Sizes.dp25(context),
  97. color: Colors.grey[800]
  98. ),
  99. ),
  100. );
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement