import 'package:flutter/material.dart';
const startAlignment = Alignment.topLeft;
const endAlignment = Alignment.bottomRight;
class GradientDecent extends StatelessWidget {
const GradientDecent( {super.key});
void rollDice(){
//....
}
@override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Colors.deepPurple,
Colors.purple],
begin: startAlignment,
end: endAlignment,
),
),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset('assets/images/dice-2.png',
width: 200,
),
// const SizedBox(20),
TextButton(onPressed: rollDice,
//use a property by calling a constructor function with an argument
style: TextButton.styleFrom(
padding: const EdgeInsets.only(
top: 20),
foregroundColor: Colors.red[500],
textStyle: const TextStyle(fontSize: 28)),
child: const Text('Roll Dice'),
), //Option 1: define function here as onPresed: (){} called annonymous function with no name
//Option 2: define a function above override with type name{} and use a function name e.g rollDice i-e not rollDice() not executing a func but just passing a pointer to function as a value to onPressed
],)
),
);
}
}
//with positional arugument (Define before super.key) // in main call in this way GradientDecent(color1,color2)
// const startAlignment= Alignment.topLeft ;
// const endAlignment = Alignment.bottomRight;
// class GradientDecent extends StatelessWidget{
// const GradientDecent(this.color1, this.color2,{super.key});
// final Color color1;
// final Color color2;
// @override
// Widget build(BuildContext context) {
// return Container(
// decoration: BoxDecoration(
// gradient: LinearGradient(
// colors: [color1,color2],
// begin: startAlignment,
// end: endAlignment,
// )),
// child: const Center(
// child: StyledText('Hello Worlddd!'),
// ),
// );
// }
// }