import 'package:flutter/material.dart';

class FlashMessage extends StatelessWidget {
  const FlashMessage({
    Key? key,
    required this.message,
  }) : super(key: key);

  final String message;

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    return Stack(
      clipBehavior: Clip.none,
      children: <Widget>[
        Container(
          padding: const EdgeInsets.all(16),
          height: 90,
          decoration: BoxDecoration(
            borderRadius: const BorderRadius.all(Radius.circular(20)),
            color: theme.colorScheme.onError,
          ),
          child: Column(
            children: <Widget>[
              Text(
                'Error',
                style: TextStyle(
                  color: theme.colorScheme.error,
                  fontSize: 18
                ),
              ),
              Text(
                message,
                style: TextStyle(
                  color: theme.colorScheme.error,
                  fontSize: 14
                ),
              ),
            ],
          ),
        ),
      ]
    );
  }
}

void showMessage(String message, BuildContext context) {
  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(
      content: FlashMessage(
        message: message,
      ),
      behavior: SnackBarBehavior.floating,
      backgroundColor: Colors.transparent,
      elevation: 0,
    ),
  );
}
