0% found this document useful (0 votes)
4 views2 pages

Checkbox & GridView

The document contains a Flutter widget named 'Checkboxs' that implements a checkbox and a grid view of colored containers. It uses a stateful widget to manage the checkbox state and displays a grid with a fixed number of items. The grid items are colored using a predefined list of colors and are arranged in a two-column layout.

Uploaded by

fouziabibi780
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Checkbox & GridView

The document contains a Flutter widget named 'Checkboxs' that implements a checkbox and a grid view of colored containers. It uses a stateful widget to manage the checkbox state and displays a grid with a fixed number of items. The grid items are colored using a predefined list of colors and are arranged in a two-column layout.

Uploaded by

fouziabibi780
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import 'package:flutter/material.

dart';

class Checkboxs extends StatefulWidget {


const Checkboxs({super.key});

@override
State<Checkboxs> createState() => _CheckboxsState();
}

class _CheckboxsState extends State<Checkboxs> {

bool option = false;


// Define a list of colors to use for the grid items
final List<Color> colors = [
Colors.red,
Colors.green,
Colors.blue,
Colors.orange,
Colors.purple,
Colors.teal,
Colors.red,
Colors.green,
Colors.blue,
Colors.orange,
Colors.purple,
Colors.teal,
];

@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
Checkbox(value: option,
onChanged: (bool? vlaue){
setState(() {
option = vlaue!;
});
}),
SizedBox(
height: 1000,
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 2,
mainAxisSpacing: 50,
crossAxisSpacing: 50
),
itemCount: 7,
itemBuilder: (BuildContext context, int index) {
return conatainer(colors[index], 20, 20) ;
},

),
)
],
),
),
);
}
Widget conatainer(Color, Height, Width){
return Container(
color: Color,
height: Height,
width: Width,
);
}
}

You might also like