alert_info 0.0.1 copy "alert_info: ^0.0.1" to clipboard
alert_info: ^0.0.1 copied to clipboard

Alert info is widget to display an animated message to user

example/lib/main.dart

import 'package:alert_info/alert_info.dart';
import 'package:example/src/switch_widget.dart';
import 'package:example/src/theme_service.dart';
import 'package:flutter/material.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool isTop = true;
  bool lightTheme = true;
  bool hasAction = false;
  TextEditingController textController = TextEditingController(
    text: 'Congratulation. this is a first animated info',
  );
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      themeMode: lightTheme ? ThemeMode.light : ThemeMode.dark,
      theme: ThemeService.lightTheme,
      darkTheme: ThemeService.darkTheme,
      home: Builder(
        builder: (context) {
          //Display the alert info
          showInfo(TypeInfo typeInfo) {
            return AlertInfo.show(
              context: context,
              text: textController.text,
              typeInfo: typeInfo,
              position: isTop ? MessagePosition.top : MessagePosition.bottom,
              action: hasAction ? 'Undo' : null,
              actionCallback: hasAction
                  ? () {
                      print('undo clicked');
                    }
                  : null,
            );
          }

          return Scaffold(
            appBar: AppBar(
              title: const Text('Alert info example'),
            ),
            body: SingleChildScrollView(
              child: Column(
                children: [
                  SwitcherWidget(
                    text: 'Top info',
                    callback: (value) {
                      setState(
                        () {
                          isTop = value;
                        },
                      );
                    },
                  ),
                  SwitcherWidget(
                    text: 'Light theme',
                    callback: (value) {
                      setState(() {
                        lightTheme = !lightTheme;
                      });
                    },
                  ),
                  SwitcherWidget(
                    text: 'With action',
                    initialState: false,
                    callback: (value) {
                      setState(() {
                        hasAction = !hasAction;
                      });
                    },
                  ),
                  const Text(
                    '--------------- Text to display ---------------',
                  ),
                  SizedBox(
                    width: 400,
                    child: TextField(
                      controller: textController,
                    ),
                  ),
                  const SizedBox(height: 30),
                  ElevatedButton(
                    onPressed: () => showInfo(TypeInfo.info),
                    child: const Text('Simple info'),
                  ),
                  const SizedBox(height: 30),
                  ElevatedButton(
                    onPressed: () => showInfo(TypeInfo.success),
                    child: const Text('Success info'),
                  ),
                  const SizedBox(height: 30),
                  ElevatedButton(
                    onPressed: () => showInfo(TypeInfo.warning),
                    child: const Text('Warning info'),
                  ),
                  const SizedBox(height: 30),
                  ElevatedButton(
                    onPressed: () => showInfo(TypeInfo.error),
                    child: const Text('Error alert'),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}
10
likes
0
points
81
downloads

Publisher

unverified uploader

Weekly Downloads

Alert info is widget to display an animated message to user

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on alert_info