Skip to content

Instantly share code, notes, and snippets.

@aysesenses
Last active January 27, 2022 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aysesenses/20a01ffcb8f48602a5a5498d3a52f764 to your computer and use it in GitHub Desktop.
Save aysesenses/20a01ffcb8f48602a5a5498d3a52f764 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: TestX(),
),
);
}
}
class TestX extends StatefulWidget {
const TestX({Key? key}) : super(key: key);
@override
State<TestX> createState() => _TestXState();
}
class _TestXState extends State<TestX> {
List<int> disableButtons = [];
@override
Widget build(BuildContext context) {
List<int> disableButtons = [];
return WillPopScope(
onWillPop: () {
return Future.value(false);
},
child: SafeArea(
child: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
flex: 4,
child: Container(
margin: const EdgeInsets.symmetric(vertical: 15),
child: Column(
children: <Widget>[
Container(
padding: const EdgeInsets.all(10.0),
child: GridView.builder(
padding: const EdgeInsets.all(16),
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.1,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
mainAxisExtent: 120),
itemCount: 6,
itemBuilder: (context, index) {
return BuildNumButton(
buttonColorDisable: Colors.green,
isDisable: disableButtons.contains(index),
callback: () {
disableButtons.add(index);
if (disableButtons.length == 6)
disableButtons.clear();
setState(() {});
},
color: Colors.cyanAccent,
number: index,
);
},
),
),
],
),
),
),
],
),
),
),
);
}
}
class BuildNumButton extends StatelessWidget {
final int number;
final Color color;
final Color buttonColorDisable;
final VoidCallback callback;
final bool isDisable;
const BuildNumButton({
Key? key,
required this.number,
required this.color,
required this.buttonColorDisable,
required this.callback,
required this.isDisable,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return SizedBox(
width: 150,
height: 120,
child: TextButton(
style: ButtonStyle(
backgroundColor: isDisable
? MaterialStateProperty.all(
buttonColorDisable) //button color green
: MaterialStateProperty.all(color),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: const BorderSide(color: Colors.white, width: 3),
),
),
),
onPressed: () {
if (widget.isDisable) {
null;
} else {
//_buttonFunction();
callback;
}
child: Text(
number.toString(),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment