flutter_switch_dark_light 0.0.4 copy "flutter_switch_dark_light: ^0.0.4" to clipboard
flutter_switch_dark_light: ^0.0.4 copied to clipboard

A package that provides a SwitchListTile widget for toggling between dark and light modes.

Flutter Switch Dark/Light #

A Flutter package to easily add a switch button to change between dark and light theme in your app.

Installation #

Add the following line to your pubspec.yaml file:

dependencies:
  flutter_switch_dark_light: ^0.0.1

Then, run flutter pub get.

Usage #

Import the package in your Dart file:

import 'package:flutter_switch_dark_light/flutter_switch_dark_light.dart';

Add the FlutterSwitchDarkLight widget to your app:

FlutterSwitchDarkLight(
  onChanged: (value) {
    //do something with isDark value
  },
  darkModeStatus: _isDarkModeEnabled,
),

Customize the widget using its parameters:

FlutterSwitchDarkLight(
  onChanged: (bool isDark) {
    // do something with isDark value
  },
  padding: const EdgeInsets.all(16.0),
  onText: 'Dark',
  offText: 'Light',
  onColor: Colors.grey[900],
  offColor: Colors.grey[200],
  activeColor: Colors.amber,
),

Parameters #

Parameter Description Default
onChanged Callback function that receives a bool value indicating if the switch is on or off. Required
padding The padding around the switch. EdgeInsets.zero
onText The text displayed when the switch is on. 'Dark'
offText The text displayed when the switch is off. 'Light'
onColor The color of the switch when it's on. Colors.grey[900]
offColor The color of the switch when it's off. Colors.grey[200]
activeColor The color of the switch's thumb when it's on. Colors.amber

Example #

import 'package:flutter/material.dart';
import 'package:flutter_switch_dark_light/flutter_switch_dark_light.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _isDarkMode = false;

  void _onThemeChanged(bool value) {
    setState(() {
      _isDarkMode = value;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Switch Dark/Light Demo',
      theme: _isDarkMode ? ThemeData.dark() : ThemeData.light(),
      home: Scaffold(
        body: Center(
          child: SwitchListTileTheme(
            onChanged: _onThemeChanged,
            onColor: Colors.black,
            offColor: Colors.white,
            activeColor: Colors.blueAccent,
          ),
        ),
      ),
    );
  }
}


1
likes
130
points
63
downloads

Publisher

unverified uploader

Weekly Downloads

A package that provides a SwitchListTile widget for toggling between dark and light modes.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on flutter_switch_dark_light