import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// Root widget of the application
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'GeeksforGeeks',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.green,
),
home: HomePage(),
);
}
}
/// StatefulWidget to toggle and show content conditionally
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool _selected = false;
/// Build method for the UI
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text('GeeksforGeeks'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
/// Checkbox tile with toggle logic
CheckboxListTile(
title: Text(
'Data Structures',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
),
value: _selected,
onChanged: (value) {
setState(() {
_selected = value ?? false;
});
},
),
SizedBox(height: 20),
/// Show content if checkbox is selected
if (_selected) ...[
Expanded(
child: ListView(
children: [
_buildTopicItem('Arrays'),
_buildTopicItem('LinkedList'),
_buildTopicItem('Stack'),
_buildTopicItem('Tree'),
],
),
),
]
],
),
),
),
);
}
/// A reusable widget to render each topic
Widget _buildTopicItem(String title) {
return Card(
elevation: 2,
margin: const EdgeInsets.symmetric(vertical: 6),
child: ListTile(
leading: Icon(Icons.bookmark),
title: Text(
title,
style: TextStyle(fontSize: 16),
),
),
);
}
}