msh_checkbox 1.1.0 copy "msh_checkbox: ^1.1.0" to clipboard
msh_checkbox: ^1.1.0 copied to clipboard

outdated

An animated checkbox, inspired by BEMCheckbox for iOS, using an API similar to Flutter's own Checkbox.

example/lib/main.dart

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

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool isChecked = false;
  bool isDisabled = false;
  MSHCheckboxStyle style = MSHCheckboxStyle.stroke;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'MSHCheckbox Example',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(title: const Text('MSHCheckbox Example')),
        body: Column(
          children: [
            Expanded(
              child: Center(
                child: MSHCheckbox(
                  size: 100,
                  value: isChecked,
                  isDisabled: isDisabled,
                  checkedColor: Colors.blue,
                  uncheckedColor: Colors.black12,
                  style: style,
                  onChanged: (selected) {
                    setState(() {
                      isChecked = selected;
                    });
                  },
                ),
              ),
            ),
            Container(
              height: 150,
              color: Colors.blue,
              child: Center(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    control(
                      "Disabled",
                      Switch(
                        value: isDisabled,
                        activeColor: Colors.white,
                        onChanged: (value) => setState(() {
                          isDisabled = value;
                        }),
                      ),
                    ),
                    control(
                      "Style",
                      Padding(
                        padding: const EdgeInsets.only(top: 8.0),
                        child: Container(
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(4),
                          ),
                          child: Padding(
                            padding:
                                const EdgeInsets.symmetric(horizontal: 8.0),
                            child: DropdownButton<MSHCheckboxStyle>(
                              isDense: true,
                              iconEnabledColor: Colors.grey,
                              dropdownColor: Colors.white,
                              underline: Container(),
                              items: MSHCheckboxStyle.values
                                  .map(
                                    (style) => DropdownMenuItem(
                                      value: style,
                                      child: Text(
                                        style.name(),
                                      ),
                                    ),
                                  )
                                  .toList(),
                              value: style,
                              onChanged: (style) => setState(() {
                                if (style != null) {
                                  this.style = style;
                                }
                              }),
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget control(String title, Widget control) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Text(
          title,
          style: const TextStyle(
            color: Colors.white,
          ),
        ),
        control,
      ],
    );
  }
}

extension StyleName on MSHCheckboxStyle {
  String name() {
    switch (this) {
      case MSHCheckboxStyle.stroke:
        return "Stroke";
      case MSHCheckboxStyle.fillScaleColor:
        return "Scale Color";
      case MSHCheckboxStyle.fillScaleCheck:
        return "Scale Check";
      case MSHCheckboxStyle.fillFade:
        return "Fade";
    }
  }
}
48
likes
0
points
2.79k
downloads

Publisher

unverified uploader

Weekly Downloads

An animated checkbox, inspired by BEMCheckbox for iOS, using an API similar to Flutter's own Checkbox.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on msh_checkbox