switch_it 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 44

switch_it #

A Package for a customised Switch Widget in Flutter !

image

Installation #

Include the package in Pubspec.yaml

switch_it: ^0.0.1

Usage #

SwitchIt(
    isEnabled: isEnabled1,
    onChanged: (value) {
        setState(() {
         isEnabled = !isEnabled;
        });
    },
),

For more refer the example app

Getting Started #

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Switch it'),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  bool isEnabled1 = true;
  bool isEnabled2 = true;
  bool isEnabled3 = true;
  bool isEnabled4 = true;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.grey[100],
        appBar: AppBar(
          title: Text(widget.title),
          centerTitle: true,
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  SwitchIt(
                    isEnabled: isEnabled4,
                    backgroundColor: Colors.green,
                    inActiveColor: Colors.grey,
                    activeColor: Colors.yellow,
                    size: 40,
                  ),
                  SwitchIt(
                    isEnabled: isEnabled1,
                    size: 60,
                    activeColor: Colors.teal,
                    inActiveColor: Colors.grey,
                    backgroundColor: Colors.tealAccent,
                  ),
                  SwitchIt(
                    isEnabled: isEnabled3,
                    backgroundColor: Colors.red,
                    inActiveColor: Colors.grey,
                    activeColor: Colors.orange,
                    size: 80,
                    onChanged: (value) {
                      setState(() {
                        isEnabled3 = !isEnabled3;
                      });
                    },
                  ),
                  SwitchIt(
                    isEnabled: isEnabled2,
                    backgroundColor: Colors.black,
                    inActiveColor: Colors.blue,
                    size: 100,
                    activeColor: Colors.white,
                    color: Colors.white,
                    onChanged: (value) {
                      setState(() {
                        isEnabled2 = !isEnabled2;
                      });
                    },
                  ),
                  SwitchIt(
                    isEnabled: isEnabled1,
                    size: 140,
                    onChanged: (value) {
                      setState(() {
                        isEnabled1 = !isEnabled1;
                      });
                    },
                  ),
                ],
              ),
              SizedBox(
                height: 40,
              ),
              Container(
                padding: EdgeInsets.only(right: 80),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Text(
                      'Size: 40',
                      style: TextStyle(fontSize: 16),
                    ),
                    Text(
                      'Size: 60',
                      style: TextStyle(fontSize: 16),
                    ),
                    Text(
                      'Size: 80',
                      style: TextStyle(fontSize: 16),
                    ),
                    Text(
                      'Size: 100',
                      style: TextStyle(fontSize: 16),
                    ),
                    Text(
                      'Size: 140',
                      style: TextStyle(fontSize: 16),
                    ),
                  ],
                ),
              )
            ],
          ),
        ));
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  switch_it: ^0.0.1

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:switch_it/switch_it.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]
70
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • switch_it that is a package requiring null.

Health suggestions

Fix lib/switch_it.dart. (-1.49 points)

Analysis of lib/switch_it.dart reported 3 hints:

line 6 col 7: This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: SwitchIt.isEnabled

line 66 col 10: The declaration '_iconSize' isn't referenced.

line 72 col 21: The value of the field '_mainAxisAlignment' isn't used.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

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