mhunt_launcher/lib/Widgets/CustomWidgets.dart
2024-05-24 23:35:54 +05:30

342 lines
10 KiB
Dart

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: -270,
left: -170,
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: -170,
right: -170,
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: -150,
child: AnimatedContainer(
duration: opDuration,
onEnd: () {
// setState(() {
op3 = (random.nextDouble() / 2) + 0.5;
log(op3);
onAnimEnd();
// });
},
height: 150,
width: 150,
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: 300, sigmaY: 300),
child:
Container(height: 10, width: 20, color: Colors.transparent),
),
),
),
Container(
margin: EdgeInsets.fromLTRB(0,0,0,bottomNav == null ? 0 : 50),
child: AnimatedContainer(duration: opDuration, child: child),
),
(bottomNav != null)
? Positioned(
bottom: 20,
right: screenWidth * 0.15,
child: Container(
width: screenWidth * 0.7,
height: 70,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomCenter,
colors: [
Colors.white.withOpacity(0.12),
Colors.white.withOpacity(0.05)
]
),
borderRadius: BorderRadius.circular(50),
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset.fromDirection(1, 2))
]),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: bottomNav,
)),
)
: SizedBox(height: 0,width: 0,),
]));
}
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(10),
gradient: LinearGradient(
begin: Alignment(0, -1),
end: Alignment(0, 1.2),
colors: colors),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
(heading == null) ? Container() : heading,
Center(child: Text(text, style: TextStyle(fontSize: fontSize))),
(trailing == null) ? Container() : trailing
],
),
),
),
),
),
);
}
Widget GlassButton({Color color = Colors.white,double height = 30,required Function() onTap, required Widget child, required double width, double opacity = 0.3}){
return InkWell(
onTap: onTap,
child: Container(width: width,height: height, decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(begin: Alignment.topLeft, end: Alignment.bottomCenter, colors: [color.withOpacity(opacity), color.withOpacity(opacity/2.5)]),
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset.fromDirection(1, 2))
],
),
child: Align(alignment: Alignment.center,child: child),),
);
}
Widget GlassCard({bool highlighted = false,Color color = Colors.white,required Widget child}) {
return Container(
// padding: EdgeInsets.all(30),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomCenter,
colors: [
color.withOpacity(highlighted ? 0.4 : 0.12),
color.withOpacity(highlighted? 0.15:0.05),
]),
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset.fromDirection(1, 2))
],
),
child: child);
}
Widget GlassContainer({required Widget child, Color color = Colors.white, double opacity = 0.12}){
return Container(
// padding: EdgeInsets.all(30),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomCenter,
colors: [
color.withOpacity(opacity),
color.withOpacity(opacity/2),
]),
boxShadow: [
BoxShadow(
color: opacity > 0 ?Colors.black26 : Colors.transparent,
offset: Offset.fromDirection(1, 2))
],
),
child: child);
}
Widget GlassProgressBar({double height = 10, required double width, required double value}){
return Stack(
children: [
Container(width: width,height: height,decoration: BoxDecoration(
gradient: LinearGradient(begin: Alignment.centerLeft, end: Alignment.centerRight, colors: [Colors.white.withOpacity(0.3), Colors.white.withOpacity(0.1)]),borderRadius: BorderRadius.circular(10)
),),
Container(width: width * value ,height: height,decoration: BoxDecoration(
gradient: LinearGradient(begin: Alignment.centerLeft, end: Alignment.centerRight, colors: [Colors.white.withOpacity(0.6), Colors.white.withOpacity(0.4)]),borderRadius: BorderRadius.circular(10)
),)
],
);
}
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.blueAccent : Colors.white.withOpacity(0.8))),
(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),
);
}
}