dev-resources.site
for different kinds of informations.
Flutter SwitchListTile and ListTile
Published at
8/9/2024
Categories
flutter
dev
flutterfire
firebase
Author
aadarshk7
Author
9 person written this
aadarshk7
open
SwitchListTile
SwitchListTile is a specialized version of ListTile that includes a switch control. It's commonly used when you want to present a setting that can be toggled on or off.
Key Features:
- Title and Subtitle: Displays a main title and a subtitle.
- Switch: Includes a switch that can be toggled.
- Control: The state of the switch can be controlled with a callback function.
- Trailing Icon: Instead of a trailing widget, it has a built-in switch.
`import 'package:flutter/material.dart';
class SwitchListTileExample extends StatefulWidget {
@override
_SwitchListTileExampleState createState() => _SwitchListTileExampleState();
}
class _SwitchListTileExampleState extends State<SwitchListTileExample> {
bool _isSwitched = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SwitchListTile Example'),
),
body: Center(
child: SwitchListTile(
title: Text('Enable Notifications'),
subtitle: Text('Receive daily updates'),
value: _isSwitched,
onChanged: (bool value) {
setState(() {
_isSwitched = value;
});
},
secondary: Icon(Icons.notifications),
),
),
);
}
}
void main() {
runApp(MaterialApp(
home: SwitchListTileExample(),
));
}
ListTile
ListTile is a more general-purpose widget that can display icons, text, and other widgets, making it highly customizable. Itβs great for building more complex list items that may need different widgets in the leading, title, subtitle, and trailing positions.
Key Features:
- Leading Icon: You can include an icon or other widget at the start.
- Title and Subtitle: Offers text elements for primary and secondary text.
- Trailing Icon/Widget: You can add an icon or another widget at the end.
- Tap Interaction: Handles taps using the onTap callback.
``import 'package:flutter/material.dart';
class SwitchListTileExample extends StatefulWidget {
@override
_SwitchListTileExampleState createState() => _SwitchListTileExampleState();
}
class _SwitchListTileExampleState extends State<SwitchListTileExample> {
bool _isSwitched = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SwitchListTile Example'),
),
body: Center(
child: SwitchListTile(
title: Text('Enable Notifications'),
subtitle: Text('Receive daily updates'),
value: _isSwitched,
onChanged: (bool value) {
setState(() {
_isSwitched = value;
});
},
secondary: Icon(Icons.notifications),
),
),
);}
}
void main() {
runApp(MaterialApp(
home: SwitchListTileExample(),
));
}`
}
}
void main() {
runApp(MaterialApp(
home: SwitchListTileExample(),
));
}
runApp(MaterialApp(
home: SwitchListTileExample(),
));
}
dev Article's
30 articles in total
Latest Trends in AI in 2025
read article
Making Python CLIs More Maintainable: A Journey with Dynamic Command Loading
read article
Latest Trends in AI in 2026
read article
Meta-Arguments and Provider in Terraform Day 10
read article
Lazyvim version 14.x in WSL
read article
How to Print in GoLang
read article
Hello Dev.to Mates!
read article
What's new in Flutter 3.27
read article
Amazon S3 Security Essentials: Protect Your Data with These Key Practices
read article
Hacktoberfest 2024: A Celebration of Open Source and Community
read article
Tech and Tools I use
read article
βπ» Stop using VS Code Use This β Cursor: The AI Code Editor
read article
Djanblog
read article
Judging the first DEV Web Game Challenge
read article
5 Key Tips for First-Time Software Outsourcing
read article
Tips and Tricks for Docker Compose: Leveraging the override Feature
read article
Flutter SwitchListTile and ListTile
currently reading
Which flutter features makes you to become a flutter developer?
read article
Flutter provides mainly 2 widgets Stateless and StatefulWidget
read article
Hello I'am from Brazil and my country recently blocked access to X (Twitter). Lets talk about it
read article
Back-End Development: Definition, Stats, & Trends To Follow In 2024
read article
Topographical surveyor in Coimbatore
read article
How do I close my DEV account
read article
Why firebase instead of other databases?
read article
Can anybody tell me which popular tech company has best UI LoginScreen?
read article
Another great neovim smooth scroll plugin
read article
Meme Monday
read article
Avoiding Common useState() Mistakes in React
read article
Frontend Challenge CSS Beach
read article
Ferramentas que nΓ£o podem faltar no setup de um(a) dev
read article
Featured ones: