flicker 0.0.5 copy "flicker: ^0.0.5" to clipboard
flicker: ^0.0.5 copied to clipboard

Yet another flushbar

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:flicker/flicker.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    final flicks = <ExampleFlick>[
      ExampleFlick(title: 'Error', show: _showFlick),
      ExampleFlick(title: 'Success', show: _showSuccess),
    ];

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('Demo'),
      ),
      body: GridView.builder(
        itemCount: flicks.length,
        padding: EdgeInsets.all(16),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 2,
          crossAxisSpacing: 16,
          mainAxisSpacing: 16,
        ),
        itemBuilder: (context, index) {
          final flick = flicks[index];
          return ElevatedButton(
            style: ElevatedButton.styleFrom(
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(16),
              ),
            ),
            onPressed: () => flick.show(context),
            child: Text(flick.title),
          );
        },
      ),
    );
  }

  Future<void> _showFlick(BuildContext context) async {
    await Flicker.of(context).show(
      duration: const Duration(seconds: 2),
      animationDuration: const Duration(milliseconds: 200),
      flick: Flick.text(
        title: 'Ааааааа Ошибка!',
        message: 'Жесть какая лютая ошибка на сервере',
        alignment: Alignment.topCenter,
        margin: const EdgeInsets.all(16),
        decoration: BoxDecoration(
          color: Colors.red,
          borderRadius: BorderRadius.circular(16),
        ),
      ),
    );
  }

  Future<void> _showSuccess(BuildContext context) async {
    await Flicker.of(context).show(
      duration: const Duration(seconds: 2),
      animationDuration: const Duration(milliseconds: 200),
      flick: Flick.text(
        height: 40,
        expanded: false,
        title: 'Данные сохранены',
        alignment: Alignment.bottomRight,
        titleAlight: TextAlign.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        margin: const EdgeInsets.all(16),
        padding: EdgeInsets.symmetric(horizontal: 12, vertical: 4),
        decoration: BoxDecoration(
          color: Colors.green,
          borderRadius: BorderRadius.circular(16),
        ),
      ),
    );
  }
}

class ExampleFlick<T> {
  const ExampleFlick({
    required this.title,
    required this.show,
  });

  final String title;
  final Future<T> Function(BuildContext context) show;
}
2
likes
140
points
54
downloads

Publisher

unverified uploader

Weekly Downloads

Yet another flushbar

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flicker