Logo

dev-resources.site

for different kinds of informations.

Flutter SwitchListTile and ListTile

Published at
8/9/2024
Categories
flutter
dev
flutterfire
firebase
Author
aadarshk7
Categories
4 categories in total
flutter
open
dev
open
flutterfire
open
firebase
open
Author
9 person written this
aadarshk7
open
Flutter SwitchListTile and ListTile

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(),
  ));
}

Enter fullscreen mode Exit fullscreen mode

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(),
  ));
}`

Enter fullscreen mode Exit fullscreen mode

}
}

void main() {
runApp(MaterialApp(
home: SwitchListTileExample(),
));
}

runApp(MaterialApp(
home: SwitchListTileExample(),
));
}

dev Article's
30 articles in total
Favicon
Latest Trends in AI in 2025
Favicon
Making Python CLIs More Maintainable: A Journey with Dynamic Command Loading
Favicon
Latest Trends in AI in 2026
Favicon
Meta-Arguments and Provider in Terraform Day 10
Favicon
Lazyvim version 14.x in WSL
Favicon
How to Print in GoLang
Favicon
Hello Dev.to Mates!
Favicon
What's new in Flutter 3.27
Favicon
Amazon S3 Security Essentials: Protect Your Data with These Key Practices
Favicon
Hacktoberfest 2024: A Celebration of Open Source and Community
Favicon
Tech and Tools I use
Favicon
βœ‹πŸ» Stop using VS Code Use This β€” Cursor: The AI Code Editor
Favicon
Djanblog
Favicon
Judging the first DEV Web Game Challenge
Favicon
5 Key Tips for First-Time Software Outsourcing
Favicon
Tips and Tricks for Docker Compose: Leveraging the override Feature
Favicon
Flutter SwitchListTile and ListTile
Favicon
Which flutter features makes you to become a flutter developer?
Favicon
Flutter provides mainly 2 widgets Stateless and StatefulWidget
Favicon
Hello I'am from Brazil and my country recently blocked access to X (Twitter). Lets talk about it
Favicon
Back-End Development: Definition, Stats, & Trends To Follow In 2024
Favicon
Topographical surveyor in Coimbatore
Favicon
How do I close my DEV account
Favicon
Why firebase instead of other databases?
Favicon
Can anybody tell me which popular tech company has best UI LoginScreen?
Favicon
Another great neovim smooth scroll plugin
Favicon
Meme Monday
Favicon
Avoiding Common useState() Mistakes in React
Favicon
Frontend Challenge CSS Beach
Favicon
Ferramentas que nΓ£o podem faltar no setup de um(a) dev

Featured ones: