import 'package:flutter/material.dart';
class BidContainer extends StatefulWidget {
final name;
BidContainer({this.name});
@override
_BidContainerState createState() => _BidContainerState();
}
class _BidContainerState extends State<BidContainer> {
bool _active = false;
void handleTap() {
setState(() {
_active = !_active;
});
}
@override
Widget build(BuildContext context) {
var names = widget.name;
return GestureDetector(
onTap: () {
setState(() {
print('$names');
_active = !_active;
});
},
child: Container(
margin: EdgeInsets.all(8),
height: 30,
width: 50,
child: Center(
child: Text(
'$names',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
),
decoration: BoxDecoration(
color: _active ? Colors.deepPurpleAccent : Colors.white,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Colors.deepPurpleAccent,
width: 1.2,
),
),
),
);
}
}
I am trying to make this button active and inactive but i am able to do this with my code which is this container which i have called with the GridView() once i tap to these container it is selected but when i scroll upward or downward after selecting to these container become unselected
Container(
height: 500,
width: 380,
decoration: BoxDecoration(
border: Border.all(
width: 4,
color: Colors.black,
),
),
child: GridView(
children: BID_DATA
.map((bidValue) => BidContainer(
name: bidValue,
))
.toList(),
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 70,
childAspectRatio: 3 / 2,
crossAxisSpacing: 5,
mainAxisSpacing: 5,
),
),
),
This is the container where i have called that Container for which i have provided the code above and BID_DATA is a list of those numbers that are showing in that contaner.

