Animation Flushbar With Gradient Color In Flutter App

admin_img Posted By Bajarangi soft , Posted On 08-10-2020

Flutter Flushbar plugin libray will work same like snackbars but the think is you can easily customize the snackbar as per you wish and it’s very much simple to use.

Animation Flushbar With Gradient Color In Flutter App

using Flutter default snackbars is not at all great now, This drawbacks of default snackbar we can solve with the use of Flutter Flushbar Library.

Animation Flushbar With Gradient Color

Step 1: 
We cannot directly remove the time stamp from Animation Flushbar With Gradient Color but using the intl.dart package we can easily filter the date stamp from time stamp. So open your flutter project’s pubspec.yaml in code

dependencies:
  flutter:
    sdk: flutter
  flushbar: ^1.10.4

step 2: 
After done saving the pubspec.yaml file, Open your flutter project root folder in Command Prompt or Terminal and execute flutter pub get command. 
flutter pub get

Step 3: 
Open your project’s main.dart file and import material.dart and  flushbar: ^1.10.4. dart package.
import 'package:flushbar/flushbar.dart';

Step 4: 
Animation Flushbar With Gradient Color  Short Code Example
custom(BuildContext context) {
  flushbar = Flushbar(
    title: 'Hello there',
    message: 'How are you?',
    duration: Duration(seconds: 30),
    flushbarPosition: FlushbarPosition.BOTTOM,
    flushbarStyle: FlushbarStyle.GROUNDED,
    reverseAnimationCurve: Curves.decelerate,
    forwardAnimationCurve: Curves.elasticInOut,
    backgroundColor: Colors.red,
    boxShadows: [
      BoxShadow(
        color: Colors.blue[800],
        offset: Offset(0.0, 2.0),
        blurRadius: 3.0,
      ),
    ],
    backgroundGradient: LinearGradient(
      colors: [Colors.blueGrey, Colors.orange],
    ),
    isDismissible: false,
    icon: Icon(
      Icons.check,
      color: Colors.pink,
    ),
    mainButton: FlatButton(
      onPressed: () {
        flushbar.dismiss();
      },
      child: Text(
        'DONE',
        style: TextStyle(color: Colors.lightGreen),
      ),
    ),
    showProgressIndicator: true,
    progressIndicatorBackgroundColor: Colors.blueGrey,
  )..show(context);
}

normal(BuildContext context) {
  Flushbar(
    title: 'Hello there',
    message: 'How are you?',
    duration: Duration(seconds: 3),
    flushbarPosition: FlushbarPosition.BOTTOM,
    flushbarStyle: FlushbarStyle.GROUNDED,
    onStatusChanged: (FlushbarStatus status) {
      switch (status) {
        case FlushbarStatus.SHOWING:
          {
            print('SHOWING');
            break;
          }
        case FlushbarStatus.IS_APPEARING:
          {
            print('IS_APPEARING');
            break;
          }
        case FlushbarStatus.IS_HIDING:
          {
            print('IS_HIDING');
            break;
          }
        case FlushbarStatus.DISMISSED:
          {
            print('DISMISSED');
            break;
          }
      }
    },
  )..show(context);
}

Complete Code For Animation Flushbar With Gradient Color  In FLutter
Main.dart
import 'package:flutter/material.dart';
import 'package:flushbar/flushbar.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: 'Flutter FlushBar Example ',
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          backgroundColor: Colors.pink,
          title: Text('Animation Gradient Flushbar '),
        ),
        body: AnimationFlushBar(),
      ),
    );
  }
}
class AnimationFlushBar extends StatefulWidget {
  final String title = "FlushBar Demo";
  @override
  AnimationFlushBarState createState() => AnimationFlushBarState();
}

class AnimationFlushBarState extends State<AnimationFlushBar> {
  Flushbar flushbar;
  custom(BuildContext context) {
    flushbar = Flushbar(
      title: 'Hello there',
      message: 'How are you?',
      duration: Duration(seconds: 30),
      flushbarPosition: FlushbarPosition.BOTTOM,
      flushbarStyle: FlushbarStyle.GROUNDED,
      reverseAnimationCurve: Curves.decelerate,
      forwardAnimationCurve: Curves.elasticInOut,
      backgroundColor: Colors.red,
      boxShadows: [
        BoxShadow(
          color: Colors.blue[800],
          offset: Offset(0.0, 2.0),
          blurRadius: 3.0,
        ),
      ],
      backgroundGradient: LinearGradient(
        colors: [Colors.blueGrey, Colors.orange],
      ),
      isDismissible: false,
      icon: Icon(
        Icons.check,
        color: Colors.pink,
      ),
      mainButton: FlatButton(
        onPressed: () {
          flushbar.dismiss();
        },
        child: Text(
          'DONE',
          style: TextStyle(color: Colors.lightGreen),
        ),
      ),
      showProgressIndicator: true,
      progressIndicatorBackgroundColor: Colors.blueGrey,
    )..show(context);
  }

  normal(BuildContext context) {
    Flushbar(
      title: 'Hello there',
      message: 'How are you?',
      duration: Duration(seconds: 3),
      flushbarPosition: FlushbarPosition.BOTTOM,
      flushbarStyle: FlushbarStyle.GROUNDED,
      onStatusChanged: (FlushbarStatus status) {
        switch (status) {
          case FlushbarStatus.SHOWING:
            {
              print('SHOWING');
              break;
            }
          case FlushbarStatus.IS_APPEARING:
            {
              print('IS_APPEARING');
              break;
            }
          case FlushbarStatus.IS_HIDING:
            {
              print('IS_HIDING');
              break;
            }
          case FlushbarStatus.DISMISSED:
            {
              print('DISMISSED');
              break;
            }
        }
      },
    )..show(context);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: EdgeInsets.all(20.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            OutlineButton(
              child: Text('Show Custom FlushBar'),
              onPressed: () {
                custom(context);
              },
            ),
          ],
        ),
      ),
    );
  }
}

 

Related Post