Skip to content

Instantly share code, notes, and snippets.

@NearHuscarl
Last active April 1, 2021 23:16
Show Gist options
  • Save NearHuscarl/29b150557e866b7910e50a84c11bb18e to your computer and use it in GitHub Desktop.
Save NearHuscarl/29b150557e866b7910e50a84c11bb18e to your computer and use it in GitHub Desktop.
// 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