项目作者: firatcetiner

项目描述 :
ListTileSwitch is simple widget that combines ListTile with a switch.
高级语言: Dart
项目地址: git://github.com/firatcetiner/list_tile_switch.git
创建时间: 2020-08-10T20:42:34Z
项目社区:https://github.com/firatcetiner/list_tile_switch

开源协议:MIT License

下载


ListTileSwitch

Build Status
Codemagic build status
Coverage Status

ListTileSwitch is a simple widget that combines ListTile with a switch. Offering 3 types of switch widgets:

  1. Switch: Material Switch from Material library on Flutter SDK.
  2. CupertinoSwitch: CupertinoSwitch from Cupertino library on Flutter SDK.
  3. A custom switch.

Demo

Tested on Android and Web but not iOS. Theoritacially it should work on iOS devices too, since this package contains nothing but pure Dart and Flutter components.

Installation

Add dependency for package on your pubspec.yaml:

  1. dependencies:
  2. list_tile_switch: <latest>

Usage

Use it as a regular ListTile widget with a bonus: the trailing widget is a switch. Covering all aspects of the ListTile and adding more with a custom switch.

Parameter Definition
double switchScale Adjusting the scale of the switch widget.
Color switchActiveColor The color of the switch when the switch is active.
bool toggleSelectedOnValueChange Deciding whether to color the ListTile when switch value is true, the selected color will be the switchActiveColor.
Color switchInactiveColor Color when the switch is inactive.
SwitchType switchType Indicating the type of switch to be displayed.
bool value Current state of the switch value.
onChanged(bool) Toggle callback for the widget.
Widget leading, Widget title, Widget subtitle, Widget isThreeLine, EdgeInsetsGeometry contentPadding, VoidCallback onLongPress, VisualDensity visualDesnsity, bool dense, bool enabled, FocusNode focusNode, bool autoFocus, bool selected, Color focusColor, Color hoverColor, MouseCursor mouseCursor Referring to the original implementation of ListTile from Flutter SDK, all of the values are mapped directly to the ListTile widget internally.

Example

  1. import 'package:flutter/material.dart';
  2. import 'package:list_tile_switch/list_tile_switch.dart';
  3. void main() {
  4. runApp(MyApp());
  5. }
  6. class MyApp extends StatelessWidget {
  7. @override
  8. Widget build(BuildContext context) {
  9. return MaterialApp(
  10. title: 'Flutter ListTileSwitch Demo',
  11. debugShowCheckedModeBanner: false,
  12. theme: ThemeData(
  13. primarySwatch: Colors.blue,
  14. visualDensity: VisualDensity.adaptivePlatformDensity,
  15. ), home: ListTileSwitchExample(title: 'Flutter ListTileSwitch Demo'),
  16. ); }}
  17. class ListTileSwitchExample extends StatefulWidget {
  18. ListTileSwitchExample({Key key, this.title}) : super(key: key);
  19. final String title;
  20. @override
  21. _ListTileSwitchExampleState createState() => _ListTileSwitchExampleState();
  22. }
  23. class _ListTileSwitchExampleState extends State<ListTileSwitchExample> {
  24. bool _value = false;
  25. @override
  26. Widget build(BuildContext context) {
  27. return Scaffold(
  28. appBar: AppBar(
  29. title: Text(widget.title),
  30. ),
  31. body: ListTileSwitch(
  32. value: _value,
  33. leading: Icon(Icons.access_alarms),
  34. onChanged: (value) {
  35. setState(() {
  36. _value = value;
  37. });
  38. },
  39. visualDensity: VisualDensity.comfortable,
  40. switchType: SwitchType.cupertino,
  41. switchActiveColor: Colors.indigo,
  42. title: Text('Default Custom Switch'),
  43. ),
  44. );
  45. }}

Todo

The list of additional features that are considered to be implemented in the future.

  • Creating more tests
  • Add interactivity to custom switch widget
  • Make custom switch more configurable
    • Configurable thumb shape
    • Configurable track shape
    • Scaling animation on value change

Contribution

Contributions are accepted via pull requests. For more information about how to contribute to this package, please check the contribution guide.

License

This project is licensed under the MIT license, additional knowledge about the license can be found here.