Source Code
   
Thanks
lib => main.dart
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
   runApp(MyApp());
}
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
  List<Color> colors = [Colors.blue, Colors.amber, Colors.pink];
  int index=0;
  Color colorrightnow;
  void changecolor() 
  {
    setState(() {
      index=Random().nextInt(colors.length); 
      colorrightnow=colors[index];
    });
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Change Color",
      home: Scaffold(
        appBar: AppBar(
          title: Text("Change Color"),
        ),
        backgroundColor: colorrightnow,
        body:Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              SizedBox(height: 20.0),
                RaisedButton(
                  splashColor: Colors.green,
                  color: Colors.red,
                  onPressed: changecolor,
                  child: Text("Click Here",
                  style: TextStyle(
                    fontSize: 20.0,
                    color: Colors.white,
                  ),
                  ),
                )
            ],
          ),  
        ),
      ),
    );
  }
}
Thanks


 
 
 
 
 
 
 Posts
Posts
 
 
 
 
 
 
 
 
 
No comments:
Post a Comment