A radio button widget for flutter that supports custom builders and a variable number of animations.

Overview

custom_radio

An animatable radio button that can be customized to the max.

I found it strange that flutter only provides two radio widgets: Radio and RadioListTile The main issue with these widgets is that both of them force the use of the default Android leading animated circular icon. This widget leaves everything up to the user by allowing them to provide their own builder function. On top of that, an animations builder can also be provided. This gets passed a parent animation controller with which the user can then use to create a list of animations that can animate the widgets transition between states.

Installation

Simply add custom_radio: ^0.1.2 as a dependancy in your pubspec.yaml file. Then import 'package:custom_radio/custom_radio.dart'; wherever you need it.

Examples

If only one animation type is required then it can be specified to enable stronger typing.

CustomRadio<String, double>(
  value: 'First',
  groupValue: widget.radioValue,
  duration: Duration(milliseconds: 500),
  animsBuilder: (AnimationController controller) => [
    CurvedAnimation(
      parent: controller,
      curve: Curves.easeInOut
    )
  ],
  builder: (BuildContext context, List<double> animValues, Function updateState, String value) {
    final alpha = (animValues[0] * 255).toInt();
    return GestureDetector(
      onTap: () {
        setState(() {
          widget.radioValue = value;
        });
      },
      child: Container(
        padding: EdgeInsets.all(32.0),
        margin: EdgeInsets.all(12.0),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: Theme.of(context).primaryColor.withAlpha(alpha),
          border: Border.all(
            color: Theme.of(context).primaryColor.withAlpha(255 - alpha),
            width: 4.0,
          )
        ),
        child: Text(
          value,
          style: Theme.of(context).textTheme.body1.copyWith(fontSize: 24.0),
        )
      )
    );
  }
)

But any combination of animation types are supported.

CustomRadio<String, dynamic>(
  value: 'First',
  groupValue: widget.radioValue,
  animsBuilder: (AnimationController controller) => [
    CurvedAnimation(
      parent: controller,
      curve: Curves.easeInOut
    ),
    ColorTween(
      begin: Colors.white,
      end: Colors.deepPurple
    ).animate(controller),
    ColorTween(
      begin: Colors.deepPurple,
      end: Colors.white
    ).animate(controller),
  ],
  builder: (BuildContext context, List<dynamic> animValues, Function updateState, String value) {
    return GestureDetector(
      onTap: () {
        setState(() {
          widget.radioValue = value;
        });
      },
      child: Container(
        alignment: Alignment.center,
        margin: EdgeInsets.all(18.0),
        padding: EdgeInsets.all(32.0 + animValues[0] * 12.0),
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: animValues[1],
          border: Border.all(
            color: animValues[2],
            width: 2.0
          )
        ),
        child: Text(
          value,
          style: Theme.of(context).textTheme.body1.copyWith(
            fontSize: 20.0,
            color: animValues[2]
          ),
        )
      )
    );
  },
)

You can even recreate the default animation provided by Radio and add your own personal flairs! Note: The full example can be found in the example directory

CustomRadio<int, double>(
  value: value,
  groupValue: widget.radioValue,
  duration: Duration(milliseconds: 400),
  animsBuilder: (AnimationController controller) => [
    CurvedAnimation(
      parent: controller,
      curve: Curves.ease
    )
  ],
  builder: ({ BuildContext context, List<double> animValues, Function updateState, bool checked }) {
    return GestureDetector(
      onTapDown: (TapDownDetails details) {
        setState(() {
          if (_controller.status != AnimationStatus.completed)
            _controller.forward();
        });
      },
      onTapUp: (TapUpDetails details) {
        setState(() {
          if (_controller.status != AnimationStatus.dismissed)
            _controller.reverse();
        });
      },
      onTap: () {
        setState(() {
          widget.radioValue = value;
        });
      },
      child: Container(
        margin: EdgeInsets.all(8.0),
        width: 38.0,
        height: 38.0,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          shape: BoxShape.circle,
        ),
        child: Stack(
          alignment: Alignment.center,
          children: <Widget>[
            Container(
              width: 38.0 * _animation.value,
              height: 38.0 * _animation.value,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                color: Theme.of(context).primaryColor.withAlpha(40)
              ),
            ),
            Container(
              width: 18.0,
              height: 18.0,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                color: Colors.transparent,
                border: Border.all(
                  color: checked ? Theme.of(context).primaryColor : Theme.of(context).hintColor,
                  width: 2.0
                )
              ),
            ),
            Container(
              width: 11.0 * animValues[0],
              height: 11.0 * animValues[0],
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                color: Theme.of(context).primaryColor,
              ),
            ),
          ]
        ),
      )
    );
  }
)

You might also like...

The application contains the Noble Qur’an, Qur’an radio stations, morning and evening remembrances, and some supplications that a Muslim needs in his life, as well as prayer times, the direction of the qiblah, and the Forty-Nawawi book

The application contains the Noble Qur’an, Qur’an radio stations, morning and evening remembrances, and some supplications that a Muslim needs in his life, as well as prayer times, the direction of the qiblah, and the Forty-Nawawi book

The application contains the Noble Qur’an, Qur’an radio stations, morning and evening remembrances, and some supplications that a Muslim needs in his life, as well as prayer times, the direction of the qiblah, and the Forty-Nawawi book

Dec 15, 2022

This repo is for anything that can be reusable in flutter like custom widgets 🟥, animations 🌟and more

Ease This packa is for anything that can be reusable in flutter like custom widgets 🟥 , animations 🌟 and more. Features 1-custom text widget to ease

Dec 3, 2022

A set of Flutter widgets that makes grouping Checkboxes and Radio Buttons much easier!

A set of Flutter widgets that makes grouping Checkboxes and Radio Buttons much easier!

grouped_buttons A set of Flutter widgets that makes grouping Checkboxes and Radio Buttons much easier! Installing Add the following to your pubspec.ya

Dec 28, 2022

An sample app demonstrating online radio streaming in flutter

An sample app demonstrating online radio streaming in flutter

Flutter Radio App Hey, This is an app demonstarting online radio streaming in flutter. Have a look. Demo Catch the demo in this video. If you like it,

Jun 28, 2022

AI Radio based on Alan AI . made with Flutter

airadio An AI - Powered Voice Assistant Flutter Radio App This is a Alan AI & Flutter based online radio application. I have built this by following c

Sep 15, 2022

Another Awesome Online Radio Player

Another Awesome Online Radio Player

kRadio Player Another Awesome Online Radio Player. Getting Started Follow the guide on how to install Flutter. Clone the repository and open with your

Nov 23, 2022

This is a radio app where you can ask Alan AI to play some music.

This is a radio app where you can ask Alan AI to play some music.

AI-Powered Voice Assistant Flutter Radio App This is a radio app where you can ask Alan AI to play some music. Alan AI: https://voice.alan.app/MTechVi

Jan 3, 2023

Flutter plugin to display a popup menu button widget with handsome design and easy to use.

Flutter plugin to display a popup menu button widget with handsome design and easy to use.

menu_button Flutter widget to display a popup menu button very simply and easily customizable. Resources Documentation Pub Package GitHub Repository I

Sep 27, 2022

Floating Action Button Widget For Flutter

Floating Action Button Widget For Flutter

Flutter Tutorial - FloatingActionButton Widget (FAB) Embed the FloatingActionBut

Dec 27, 2021
Comments
  • Error while run the project

    Error while run the project

    ../../flutter/.pub-cache/hosted/pub.dartlang.org/custom_radio-0.1.2/lib/custom_radio.dart:102:36: Error: The argument type 'Null Function(Null)' can't be assigned to the parameter type 'dynamic Function(void)'. [ ] _controller.reverse().then((Null value) {

    opened by BriscoPeas93 5
  • Request to Add Product in Start Flutter

    Request to Add Product in Start Flutter

    Hello,

    I am Maheshwari from team GeekyAnts. On behalf of Start Flutter, we add open source products which we find helpful to the community & also we provide credits to author itself.

    Let me know if you are interested showcase your product in our open source website.

    Looking forward to hear from you.

    opened by maheshwari-1153 0
Owner
Conrad Heidebrecht
I'm a Systems Design Engineering Student at the University of Waterloo interested in web & Android development and machine learning.
Conrad Heidebrecht
A customizable carousel slider widget in Flutter which supports inifinte scrolling, auto scrolling, custom child widget, custom animations and built-in indicators.

flutter_carousel_widget A customizable carousel slider widget in Flutter. Features Infinite Scroll Custom Child Widget Auto Play Horizontal and Vertic

NIKHIL RAJPUT 7 Nov 26, 2022
A radio component suitable for almost any radio scenario.

fradio A radio component suitable for almost any radio scenario. Supports excellent interactive special effects, as well as a simple multi-interactive

Fliggy Mobile 75 Nov 26, 2022
Add beautiful animated effects & builders in Flutter, via an easy, highly customizable unified API.

Flutter Animate A performant library that makes it simple to add almost any kind of animated effect in Flutter. Pre-built effects, like fade, scale, s

Grant Skinner 352 Dec 25, 2022
Flutter package to create list of radio button, by providing a list of objects it can be a String list or list of Map.

Custom Radio Group List Flutter package to create list of radio button, by providing a list of objects it can be a String list or list of Map. Feature

Ashok Kumar Verma 0 Nov 30, 2021
Custom dropdown widget allows to add highly customizable widget in your projects with proper open and close animations and also comes with form required validation.

Custom Dropdown Custom Dropdown package lets you add customizable animated dropdown widget. Features Lots of properties to use and customize dropdown

Abdullah Chauhan 22 Dec 29, 2022
Swipeable button view - Create Ripple Animated Pages With Swipeable Button View

swipeable_button_view You can create ripple animated pages with swipeable_button

cemreonur 3 Apr 22, 2022
FT-Custom-Widget - A Custom Widget Built With Flutter

Custom Widget Watch it on YouTube Product Screen Sample when you implement compl

Firgia 5 Mar 29, 2022
Flutter custom carousel slider - A carousel slider widget,support custom decoration suitable for news and blog

flutter_custom_carousel_slider A carousel slider Flutter widget, supports custom

Emre 40 Dec 29, 2022
MindInventory 15 Sep 5, 2022
A Custom 3D Button in Flutter

Clicky Button for flutter A Custom 3D Button in Flutter Demo How To Use it import 'clicky_button/clicky_button.dart' ... ClickyButton( child: Tex

Raj Singh 16 Sep 2, 2022