On clicking the Go button I want button 1 to turn red. Then turn back white. Then button 2 should turn red & then reverts back to white. Then 3, 4 and so on.
I can design my callback button such that button 1 turns red. I am not sure, how to turn it back to white after 2 second & then turn the next button red & so on.
main.dart
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final String apptitle = 'Test';
Widget _goButtonClickCallback() {
print("hello world. go tapped");
// How do I control animation inside numListBuilder() from here?
}
@override
Widget build(BuildContext context) {
var numList = [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
];
return MaterialApp(
title: apptitle,
theme: ThemeData(
primarySwatch: Colors.deepOrange,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Scaffold(
appBar: AppBar(
title: Text(apptitle),
),
body: Column(
children: [
NumberListBuilder(numList),
SizedBox(height: 110),
GoButton(_goButtonClickCallback)
],
)),
);
}
}
NumberListBuilder.dart
import 'package:flutter/material.dart';
class NumberListBuilder extends StatefulWidget {
final List<String> numberList;
const NumberListBuilder(this.numberList);
@override
_NumberListBuilderState createState() => _NumberListBuilderState();
}
class _NumberListBuilderState extends State<NumberListBuilder> {
List<TableRow> getButtonRows() {
// list for all rows
List<TableRow> rows = [];
int numCols = 2;
int numberListLength = widget.numberList.length;
int numRows = 4
var k = 0;
for (var i = 0; i < numRows; i++) {
List<Widget> rowChildren = [];
for (var j = 0; j < numCols; j++) {
rowChildren.add(Container(
height: 80.0,
child: FlatButton(
color: Colors.white70,
onPressed: () {},
child: Text(
widget.numberList[k++],
style: TextStyle(
fontSize: 20.0,
),
),
)));
}
rows.add(new TableRow(children: rowChildren));
}
return rows;
}
@override
Widget build(BuildContext context) {
return new Container(
child: new Table(
border: TableBorder.all(),
children: getButtonRows(),
),
);
}
}
