flutter_reactive_button 1.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 79

ReactiveButton

A Widget that mimics the Facebook Reaction Button in Flutter.

Flutter ReactiveButton


Step by step explanation

A full explanation on how to build such Widget may be found on my blog:

  • in English, click here
  • in French, click here

Getting Started

You should ensure that you add the following dependency in your Flutter project.

dependencies:
 flutter_reactive_button: "^1.0.0"

You should then run flutter packages upgrade or update your packages in IntelliJ.

In your Dart code, to use it:

import 'package:flutter_reactive_button/flutter_reactive_button.dart';

Icons

Icons should be defined as assets and passed to the ReactiveButton Widget, via the icons property, which accepts a List < ReactiveIconDefinition >.


Example

An example can be found in the example folder. Check it out.

[0.1.0] - 2018-09-08

  • initial release

[1.0.0] - 2018-09-08

  • code formatting

example/main.dart

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

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Reactive Button Demo',
      debugShowCheckedModeBanner: false,
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new PageReactiveButton(),
    );
  }
}

// ----------------------------------------------------------------

class PageReactiveButton extends StatefulWidget {
  @override
  _PageReactiveButtonState createState() => _PageReactiveButtonState();
}

class _PageReactiveButtonState extends State<PageReactiveButton> {
  List<ReactiveIconDefinition> _flags = <ReactiveIconDefinition>[
    ReactiveIconDefinition(
      assetIcon: 'images/flag-de.png',
      code: 'de',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/flag-en.png',
      code: 'en',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/flag-fr.png',
      code: 'fr',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/flag-it.png',
      code: 'it',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/flag-nl.png',
      code: 'nl',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/flag-es.png',
      code: 'es',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/flag-pt.png',
      code: 'pt',
    ),
  ];

  List<ReactiveIconDefinition> _facebook = <ReactiveIconDefinition>[
    ReactiveIconDefinition(
      assetIcon: 'images/like.gif',
      code: 'like',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/haha.gif',
      code: 'haha',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/love.gif',
      code: 'love',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/sad.gif',
      code: 'sad',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/wow.gif',
      code: 'wow',
    ),
    ReactiveIconDefinition(
      assetIcon: 'images/angry.gif',
      code: 'angry',
    ),
  ];

  String countryCode = 'en';
  String facebook;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ReactiveButton Sample'),
        actions: <Widget>[
          ReactiveButton(
            icons: _flags,
            onSelected: (ReactiveIconDefinition button) {
              setState(() {
                countryCode = button.code;
              });
            },
            child: Image.asset(
              'images/flag-$countryCode.png',
              width: 32.0,
              height: 32.0,
            ),
            containerAbove: false,
            iconWidth: 32.0,
            iconGrowRatio: 1.5,
            roundIcons: false,
            onTap: () {
              print('Hey I am hit');
            },
            decoration: BoxDecoration(
              border: Border.all(
                width: 1.0,
                color: Colors.black54,
              ),
              borderRadius: BorderRadius.circular(10.0),
              color: Color(0x55FFFFFF),
            ),
          ),
          SizedBox(
            width: 24.0,
          )
        ],
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Column(
          children: <Widget>[
            Container(
              height: 850.0,
              color: Colors.blueGrey,
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text('Here is some text'),
            ),
            ReactiveButton(
              child: Container(
                decoration: BoxDecoration(
                  border: Border.all(
                    color: Colors.black,
                    width: 1.0,
                  ),
                  color: Colors.white,
                ),
                width: 80.0,
                height: 40.0,
                child: Center(
                  child: facebook == null
                      ? Text('click')
                      : Image.asset(
                          'images/$facebook.png',
                          width: 32.0,
                          height: 32.0,
                        ),
                ),
              ),
              icons: _facebook, //_flags,
              onTap: () {
                print('TAP');
              },
              onSelected: (ReactiveIconDefinition button) {
                setState(() {
                  facebook = button.code;
                });
              },
              iconWidth: 32.0,
            ),
            Container(
              height: 800.0,
              color: Colors.blueGrey,
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_reactive_button: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_reactive_button/flutter_reactive_button.dart';
  
Version Uploaded Documentation Archive
1.0.0 Sep 8, 2018 Go to the documentation of flutter_reactive_button 1.0.0 Download flutter_reactive_button 1.0.0 archive
0.1.0 Sep 8, 2018 Go to the documentation of flutter_reactive_button 0.1.0 Download flutter_reactive_button 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
58
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on Oct 26, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0-dev.7.1.flutter-b99bcfd309
  • pana: 0.12.5
  • Flutter: 0.10.1

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/src/widget_position.dart.

Run flutter format to format lib/src/widget_position.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
rxdart ^0.18.1 0.18.1 0.19.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test