Skip to content

Instantly share code, notes, and snippets.

@omarzer0
Created December 15, 2022 17:04
Show Gist options
  • Save omarzer0/eb32b768a5fa48dfed02c604a1902402 to your computer and use it in GitHub Desktop.
Save omarzer0/eb32b768a5fa48dfed02c604a1902402 to your computer and use it in GitHub Desktop.
import 'package:another_flushbar/flushbar.dart';
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
showSemanticsDebugger: false,
home: LoginScreen(),
),
);
}
class LoginScreen extends StatefulWidget {
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
Flushbar? flushbar;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
children: [ElevatedButton(onPressed: () {
msg();
}, child: Text('Alert')),
],
),
);
}
void msg() {
Flushbar(
title: 'Error',
message: 'Invalid username or password',
duration: Duration(seconds: 4),
icon: Icon(
Icons.highlight_remove_outlined,
size: 28,
color: Colors.white,
),
backgroundColor: Colors.red,
flushbarPosition: FlushbarPosition.TOP,
margin: EdgeInsets.symmetric(horizontal: 10),
borderRadius: BorderRadius.circular(8),
);
flushbar?.show(context);
}
/**
* msg method version to stop duplicate flush showing
* (cancels the old one and start a new one)*/
// void msg() {
// flushbar?.dismiss();
// flushbar = Flushbar(
// title: 'Error',
// message: 'Invalid username or password',
// duration: Duration(seconds: 4),
// icon: Icon(
// Icons.highlight_remove_outlined,
// size: 28,
// color: Colors.white,
// ),
// backgroundColor: Colors.red,
// flushbarPosition: FlushbarPosition.TOP,
// margin: EdgeInsets.symmetric(horizontal: 10),
// borderRadius: BorderRadius.circular(8),
// );
// flushbar?.show(context);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment