byswitcher 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new50

BySwitcher #

pub package author

A Switch Button for Flutter.

Feature #

  • 参考Flutter自带Switch实现,增加了“加载中”的状态,适用于开关需要网络请求的场景;
  • 可自定义开关底图(例如:开/关);
  • 可自定义按钮图

Get Started #

Add Dependency #

dependencies:
  byswitcher: ^1.0.0

Usage #

import 'package:byswitcher/byswitcher.dart';

/// Normal Switcher
child: BySwitcher();

/// Has Loading State Default 
child: BySwitcher.loading();

Support or Contact #

1.0.0 - 2020/06/28 #

example/lib/main.dart

import 'package:byswitcher/byswitcher.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'base/page_widget.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pandora Demo',
      theme: ThemeData(
        primarySwatch: Colors.lightGreen,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends BasePageWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends BasePageState<MyHomePage> {
  var _switchState;

  @override
  String getTitle() {
    // TODO: implement getTitle
    return 'Switcher Demo';
  }

  @override
  void initParams() {
    super.initParams();
  }

  @override
  buildBody() => Container(
        padding: EdgeInsets.all(16.0),
        color: Color(0xFFF9FCF8),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            BySwitcher.loading(
              thumbColor: Colors.white,
              state: _switchState,
              onChanged: (targetState) {
                setState(() {
                  _switchState = targetState;
                });
              },
              onLoading: (targetState) => Future.delayed(
                Duration(seconds: 3),
                () => setState(() {
                  _switchState = targetState;
                }),
              ),
            ),
            SizedBox(height: 12.0),
            BySwitcher.loading(
              thumbColor: Colors.white,
              activeTrackColor: Color(0xFF2AD182),
              inactiveTrackColor: Color(0xFFE7E6E9),
              withBorder: false,
              state: _switchState,
              inactiveFlag: Icon(Icons.clear),
              activeFlag: Icon(Icons.check, color: Colors.white),
              progressImg: Image.asset(
                'images/ic_loading_circle.webp',
                alignment: Alignment.center,
              ),
              onChanged: (targetState) {
                setState(() {
                  _switchState = targetState;
                });
              },
              onLoading: (targetState) => Future.delayed(
                Duration(seconds: 2),
                () => setState(() {
                  _switchState = targetState;
                }),
              ),
            ),
            SizedBox(height: 12.0),
            BySwitcher(
              width: 166,
              thumbColor: Colors.white,
              activeTrackColor: Colors.cyan,
              inactiveTrackColor: Color(0xFFE7E6E9),
              thumb: Icon(Icons.sentiment_neutral, color: Colors.cyan),
              inactiveFlag: Icon(Icons.sentiment_dissatisfied, color: Colors.red),
              activeFlag: Icon(Icons.sentiment_satisfied, color: Colors.white),
              state: _switchState,
              onChanged: (targetState) {
                setState(() {
                  _switchState = targetState;
                });
              },
            ),
          ],
        ),
      );
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  byswitcher: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:byswitcher/byswitcher.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • byswitcher that is a package requiring null.

Health suggestions

Fix lib/byswitcher.dart. (-1 points)

Analysis of lib/byswitcher.dart reported 2 hints:

line 168 col 8: The value of the field '_isDragging' isn't used.

line 169 col 8: The value of the field '_needsMoveAnimation' isn't used.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test