Skip to content

Instantly share code, notes, and snippets.

@isaacadariku
Last active January 24, 2022 23:15
Show Gist options
  • Save isaacadariku/59ab2905000a02a2a012481d46da8198 to your computer and use it in GitHub Desktop.
Save isaacadariku/59ab2905000a02a2a012481d46da8198 to your computer and use it in GitHub Desktop.
A checked container that checked when tap
import 'package:flutter/material.dart';
void main() {
runApp(Amenties());
}
class CheckContainer extends StatefulWidget {
const CheckContainer({Key? key, this.title = ''}) : super(key: key);
final String title;
@override
State<StatefulWidget> createState() {
return _CheckContainerState();
}
}
class _CheckContainerState extends State<CheckContainer> {
bool isChecked = false;
@override
Widget build(BuildContext context) {
return InkWell(
splashColor: Colors.cyanAccent,
onTap: () {
setState(() {
isChecked = !isChecked;
});
},
child: Container(
padding: const EdgeInsets.all(12),
color: isChecked ? Colors.blue : Colors.white,
child: Text(
widget.title,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
color: isChecked ? Colors.white : Colors.black,
),
),
),
);
}
}
class Amenties extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
title: const Text("Sunflower"),
),
body: Center(
child: Wrap(
spacing: 5.0,
runSpacing: 5.0,
children: const [
CheckContainer(title: 'Gas Cooker'),
CheckContainer(title: 'Washing Machine'),
CheckContainer(title: 'Wifi'),
CheckContainer(title: 'Television'),
CheckContainer(title: 'Water Heater'),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment