Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'dart:math';
  3.  
  4. class App extends StatefulWidget {
  5. createState() {
  6. return Colore();
  7. }
  8. }
  9.  
  10. class Colore extends State<App> {
  11. List colors = [Colors.red, Colors.green, Colors.yellow];
  12. Random random = new Random();
  13.  
  14. int index = 0;
  15.  
  16. void changeIndex() {
  17. setState(() => index = random.nextInt(3));
  18. }
  19.  
  20. Widget build(BuildContext context) {
  21. return MaterialApp(
  22. home: Scaffold(
  23. appBar: AppBar(
  24. backgroundColor: Color(Colors.orange),
  25. title: Text('DisColor'),
  26. ),
  27. floatingActionButton: FloatingActionButton(
  28. child: Icon(Icons.explore),
  29. onPressed: () {
  30. changeIndex();
  31. },
  32. backgroundColor: Color(Colors.amber),),
  33. body: Container(
  34. color: colors[index],
  35. ),
  36. ),
  37. );
  38. }
  39. }
  40.  
  41. void main() {
  42. runApp(App());
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement