JulyWitch / animated_snack_bar

Easily show beautiful snack bars directly using overlays. Create custom snack bars and show them with awesome animations.
https://pub.dev/packages/animated_snack_bar
GNU General Public License v3.0
17 stars 12 forks source link

AnimatedSnackBar

A Flutter package to show beautiful animated snackbars directly using overlay.

Features

Getting started

Add package to pubspec.yaml

flutter pub add animated_snack_bar

Import the package

import 'package:animated_snack_bar/animated_snack_bar.dart';

Usage

AnimatedSnackBar.material(
    'This a snackbar with info type',
    type: AnimatedSnackBarType.info,
).show(context);
AnimatedSnackBar.rectangle(
'Success',
  'This is a success snack bar',
  type: AnimatedSnackBarType.success,
  brightness: Brightness.light,
).show(
  context,
);
AnimatedSnackBar.rectangle(
'Success',
  'This is a success snack bar',
  type: AnimatedSnackBarType.success,
  brightness: Brightness.dark,
).show(context);
final snackbar = AnimatedSnackBar(
    builder: ((context) {
        return Container(
            padding: const EdgeInsets.all(8),
            color: Colors.amber,
            height: 50,
            child: const Text('A custom snackbar'),
        );
    }),
);
snackbar.show(context);

snackbar.remove()
AnimatedSnackBar.removeAll();
AnimatedSnackBar(
    builder: ((context) {
        return Container(
            padding: const EdgeInsets.all(8),
            color: Colors.amber,
            height: 50,
            child: const Text('A custom snackbar'),
        );
    }),
).show(context);
AnimatedSnackBar(
  builder: ((context) {
    return const MaterialAnimatedSnackBar(
      titleText: 'Custom material snackbar ',
      messageText:
          'This a custom material snackbar with info type',
      type: AnimatedSnackBarType.info,
      foregroundColor: Colors.amber,
      titleTextStyle: TextStyle(
        color: Colors.brown,
      ),
    );
  }),
).show(context);
AnimatedSnackBar.material(
    'This a snackbar with info type',
    type: AnimatedSnackBarType.info,
    mobileSnackBarPosition: MobileSnackBarPosition.bottom, // Position of snackbar on mobile devices
    desktopSnackBarPosition: DesktopSnackBarPosition.topRight, // Position of snackbar on desktop devices
).show(context);
AnimatedSnackBar.material(
    'This a snackbar with info type',
    type: AnimatedSnackBarType.info,
    mobilePositionSettings: const MobilePositionSettings(
      topOnAppearance: 100,
      // topOnDissapear: 50,
      // bottomOnAppearance: 100,
      // bottomOnDissapear: 50,
      // left: 20,
      // right: 70,
    ),
).show(context);

Multiple snack bars handling

You can pass snackBarStrategy as a paramter to determine what should snack bar do with snackbars which came before it.