

import 'dart:math';
import 'dart:ui';

import 'package:flutter/material.dart';
double op1 = 0;
double op2 = 0;
double op3 = 0;
Widget CustomBody({required Widget child,required BuildContext context, required Function() onAnimEnd, List<BottomNavBarItem>? bottomNav}) {
  Duration opDuration = const Duration(milliseconds: 1500);
  var random = new Random();


  final screenHeight = MediaQuery.of(context).size.height;
  final screenWidth = MediaQuery.of(context).size.width;

  return SizedBox(
      height: screenHeight,
      width: screenWidth,
      child: Stack(children: [
        Positioned(
          top: -100,
          left: -100,
          child: AnimatedContainer(
            duration: opDuration,
            onEnd: () {
              op1 = (random.nextDouble() / 2) + 0.5;
              log(op1);
              onAnimEnd();
            },
            height: 400,
            width: 200,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              gradient: RadialGradient(
                colors: [
                  Colors.blue.withOpacity(0.3 + (op1/3)),
                  Colors.blue.withOpacity(op1),
                  Colors.deepPurpleAccent.withOpacity(op1)
                ],
              ),
            ),
            child: BackdropFilter(
              filter: ImageFilter.blur(sigmaX: 200, sigmaY: 200),
              child: Container(
                  height: 200, width: 200, color: Colors.transparent),
            ),
          ),
        ),
        Positioned(
          bottom: -25,
          right: -100,
          child: AnimatedContainer(
            duration: opDuration,
            onEnd: () {
              // setState(() {
                op2 = (random.nextDouble() / 2) + 0.5;
                log(op2);              onAnimEnd();

              // });
            },
            height: 200,
            width: 200,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              // color: Colors.deepPurple.withOpacity(0.3),
              gradient: RadialGradient(
                colors: [
                  Colors.deepPurple.withOpacity(op2),
                  Colors.purpleAccent.withOpacity(op2)
                ],
              ),
            ),
            child: BackdropFilter(
              filter: ImageFilter.blur(sigmaX: 200, sigmaY: 200),
              child: Container(
                  height: 200, width: 200, color: Colors.transparent),
            ),
          ),
        ),
        Positioned(
          top: screenHeight * 0.55,
          left: -100,
          child: AnimatedContainer(
            duration: opDuration,
            onEnd: () {
              // setState(() {
                op3 = (random.nextDouble() / 2) + 0.5;
                log(op3);              onAnimEnd();

              // });
            },
            height: 200,
            width: 200,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              // color: Colors.deepPurple.withOpacity(0.3),
              gradient: RadialGradient(
                colors: [
                  Colors.red.withOpacity(op3),
                  Colors.red.withOpacity(op3)
                ],
              ),
            ),
            child: BackdropFilter(
              filter: ImageFilter.blur(sigmaX: 200, sigmaY: 200),
              child: Container(
                  height: 200, width: 200, color: Colors.transparent),
            ),
          ),
        ),
        (bottomNav != null) ? Positioned(
          bottom: 20,
          right: screenWidth * 0.15,
          child: Container(
              width: screenWidth * 0.7,
              height: 70,
              decoration: BoxDecoration(
                  color: Colors.black,
                  borderRadius: BorderRadius.circular(50),
                  boxShadow: [
                    BoxShadow(
                        color: Colors.black26, offset: Offset.fromDirection(1, 2))
                  ]),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: bottomNav,
              )),
        ) : Container(),
        AnimatedContainer(duration: opDuration,child: child)
      ]));
}




Widget NeonButton(
    {required void Function() onPressed,
      required String text,
      double width = 250,
      double height = 50,
      double fontSize = 20,
      List<Color>? colors,
      Widget? trailing,
      Widget? heading}) {
  if(colors == null){
    colors = [Colors.blue, Colors.deepPurple];
  }
  return Padding(
    padding: const EdgeInsets.all(8.0),
    child: SizedBox(
      width: width,
      height: height,
      child: InkWell(
        onTap: onPressed,
        child: Container(
          decoration: BoxDecoration(
            boxShadow: [
              BoxShadow(
                color: Colors.deepPurple.withOpacity(0.4),
                spreadRadius: 5,
                blurRadius: 50,
                offset: Offset(0, 0),
              ),
              BoxShadow(
                  color: Colors.white.withOpacity(0.6),
                  spreadRadius: 0.3,
                  offset: Offset(0.2, -0.3))
            ],
            borderRadius: BorderRadius.circular(50),
            gradient: LinearGradient(
                begin: Alignment(0, -1),
                end: Alignment(0, 1.2),
                colors: colors),
          ),
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 15.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                (heading == null) ? Container() : heading,
                Center(child: Text(text, style: TextStyle(fontSize: fontSize))),
                (trailing == null) ? Container() : trailing
              ],
            ),
          ),
        ),
      ),
    ),
  );
}

class BottomNavBarItem extends StatelessWidget {
  BottomNavBarItem({required this.active,required IconData this.icon, String? this.text, required Function() this.onPressed,});
  IconData icon;
  String? text;
  Function() onPressed;
  bool active = false;
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return InkWell(
      onTap: (){
        onPressed();
      },
      child: Container(
        margin: EdgeInsets.all(10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            AnimatedSize(duration: const Duration(milliseconds: 300),child: Icon(icon,size:active ? 45 : 25, color: active ? Colors.deepPurpleAccent : Colors.blue)),
            (text!=null) ? Text(text!) : Container()
          ],
        ),
      ),
    );
  }
}

class GradientText extends StatelessWidget {
  const GradientText(
       {super.key, required this.text,
        required this.gradient,
        this.style,
      });

  final String text;
  final TextStyle? style;
  final Gradient gradient;

  @override
  Widget build(BuildContext context) {
    return ShaderMask(
      blendMode: BlendMode.srcIn,
      shaderCallback: (bounds) => gradient.createShader(
        Rect.fromLTWH(0, 0, bounds.width, bounds.height),
      ),
      child: Text(text, style: style),
    );
  }
}