Search code examples
flutterdartflutter-layout

How can change content of specifice container in Gridview


I try to create this type of design on containers which are present in gridview

how can I make as it is show in figure -

enter image description here

Here is the code -

Container(
height: 130,
child: GridView.builder(
itemCount: 4,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
    crossAxisCount: 4,
    crossAxisSpacing: 10
    ),
itemBuilder: (BuildContext context, int index) {
    return Container(
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10.0),
            border: Border.all(width: right_anscontainer == index ? 2.0 : 1.0,
            color: right_anscontainer == index ? Color(0xff148F6A) : Colors.black26,),
            ),
        child: Stack(
            children: [
                Icon(Icons.image, color: right_anscontainer == index ? Color(0xff148F6A) : Colors.black26,),
                Positioned(
                child: right_anscontainer == index ? Icon(Icons.check_circle, color: Color(0xff148F6A), size: 20,) : SizedBox(height: 0,),
                )
            ],
        ),
    );
},
),),

Solution

  • You need to do the same thing you did for green container. Create left_anscontainer and changes like this:

    return Container(
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10.0),
                border: Border.all(width: right_anscontainer == index || left_anscontainer == index ? 2.0 : 1.0,
                color: right_anscontainer == index ? Color(0xff148F6A) : left_anscontainer == index ? Colors.red : Colors.black26,),
            ),
            child: Stack(
                children: [
                    Icon(Icons.image, color: right_anscontainer == index ? Color(0xff148F6A) : left_anscontainer == index ? Colors.red : Colors.black26,),
                    Positioned(
                       child: right_anscontainer == index || left_anscontainer == index? Icon(left_anscontainer == index ? Icons.close :Icons.check_circle, color: left_anscontainer == index ? Colors.red : Color(0xff148F6A), size: 20,) : SizedBox(height: 0,),
                    )
                ],
            ),
        )