showText function
Information dialog Shows a flash dialog or a simple dialog with @isFlash = false
Implementation
Future<void> showText(BuildContext context, String text, String subtitle,
{Color? backgroundColor,
int seconds = 5,
Widget? leading,
List<Widget>? trailing,
Function? onTap,
bool isNotification = false,
bool isFlash = true}) async {
try {
if (isFlash) {
showFlash(
context: context,
duration: Duration(seconds: seconds),
transitionDuration: Duration(seconds: isNotification ? 2 : 1),
builder: (context, controller) {
return Flash(
forwardAnimationCurve: Curves.elasticInOut,
reverseAnimationCurve: Curves.elasticInOut,
controller: controller,
position: FlashPosition.bottom,
child: GestureDetector(
onTap: () {
if (onTap != null) onTap();
},
child: FlashBar(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(!isNotification ? 0 : 20))),
margin: !isNotification
? EdgeInsets.zero
: const EdgeInsets.all(20),
shouldIconPulse: false,
icon: SizedBox(height: 30, width: 30, child: leading),
actions: trailing,
backgroundColor: backgroundColor ?? Colors.blue[800],
title: Text(
text,
style: const TextStyle(color: Colors.white, fontSize: 20),
),
content: Text(
subtitle,
style: const TextStyle(color: Colors.white70, fontSize: 16),
),
controller: controller,
),
),
);
},
);
} else {
showDialog<bool>(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return SimpleDialog(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
children: <Widget>[
Padding(
padding: const EdgeInsets.all(20.0),
child: Text(
text,
style: TextStyle(color: Colors.green[900], fontSize: 25),
),
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Text(
subtitle,
style: TextStyle(color: Colors.brown[900], fontSize: 15),
),
),
Padding(
padding: const EdgeInsets.all(30.0),
child: ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"OK",
style: TextStyle(color: Colors.white, fontSize: 18),
),
),
),
),
],
);
},
);
}
} catch (err) {
if (kDebugMode) {
print(err);
}
}
}