Last active
April 1, 2021 23:16
-
-
Save NearHuscarl/29b150557e866b7910e50a84c11bb18e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://gist.github.com/NearHuscarl/29b150557e866b7910e50a84c11bb18e | |
// https://dartpad.dev/29b150557e866b7910e50a84c11bb18e?null_safety=true | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
void main1() { | |
const a = <String>[]; | |
a.add('1'); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
ElevatedButton( | |
onPressed: () {}, | |
child: Text('Button 1'), | |
style: ButtonStyle( | |
backgroundColor: MaterialStateProperty.all(Colors.purple), | |
), | |
), | |
SizedBox(height: 10), | |
ElevatedButton( | |
onPressed: () {}, | |
child: Text('Button 2'), | |
style: ButtonStyle( | |
backgroundColor: MaterialStateProperty.resolveAs( | |
Colors.green, {MaterialState.hovered}), | |
), | |
), | |
SizedBox(height: 10), | |
ElevatedButton( | |
onPressed: () {}, | |
child: Text('Button 3'), | |
style: ButtonStyle( | |
backgroundColor: MaterialStateProperty.resolveWith<Color>( | |
(states) { | |
if (states.contains(MaterialState.hovered)) { | |
return Colors.orange; | |
} else if (states.contains(MaterialState.pressed)) { | |
return Colors.red; | |
} | |
return Colors.amber; | |
}, | |
), | |
), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment