Add base interactive layout "rive" whit animation

This commit is contained in:
paoloGuagnano
2024-03-08 12:15:47 +01:00
parent 06336bd3d9
commit 2d5fba8897
58 changed files with 1946 additions and 133 deletions

View File

@@ -0,0 +1,49 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
class AnimatedBtn extends StatelessWidget {
const AnimatedBtn({
Key? key,
required RiveAnimationController btnAnimationController,
required this.press,
}) : _btnAnimationController = btnAnimationController,
super(key: key);
final RiveAnimationController _btnAnimationController;
final VoidCallback press;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: press,
child: SizedBox(
height: 64,
width: 236,
child: Stack(
children: [
RiveAnimation.asset(
"assets/RiveAssets/button.riv",
controllers: [_btnAnimationController],
),
Positioned.fill(
top: 8,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Icon(CupertinoIcons.arrow_right),
const SizedBox(width: 8),
Text(
"Start the course",
style: Theme.of(context).textTheme.labelLarge,
)
],
),
)
],
),
),
);
}
}

View File

@@ -0,0 +1,161 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'sign_in_form.dart';
void showCustomDialog(BuildContext context, {required ValueChanged onValue}) {
showGeneralDialog(
context: context,
barrierLabel: "Barrier",
barrierDismissible: true,
barrierColor: Colors.black.withOpacity(0.5),
transitionDuration: const Duration(milliseconds: 400),
pageBuilder: (_, __, ___) {
return Center(
child: Container(
height: 670,
margin: const EdgeInsets.symmetric(horizontal: 16),
padding: const EdgeInsets.symmetric(vertical: 32, horizontal: 24),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.95),
borderRadius: BorderRadius.circular(40),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
offset: const Offset(0, 30),
blurRadius: 60,
),
const BoxShadow(
color: Colors.black45,
offset: Offset(0, 30),
blurRadius: 60,
),
],
),
child: Scaffold(
// backgroundColor: Colors.transparent,
body: Stack(
clipBehavior: Clip.none,
children: [
SingleChildScrollView(
child: Column(
children: [
const Text(
"Sign in",
style: TextStyle(
fontSize: 34,
fontFamily: "Poppins",
fontWeight: FontWeight.w600,
),
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 16),
child: Text(
"Access to 240+ hours of content. Learn design and code, by building real apps with Flutter and Swift.",
textAlign: TextAlign.center,
),
),
const SignInForm(),
const Row(
children: [
Expanded(
child: Divider(),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Text(
"OR",
style: TextStyle(
color: Colors.black26,
fontWeight: FontWeight.w500,
),
),
),
Expanded(child: Divider()),
],
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 24),
child: Text(
"Sign up with Email, Apple or Google",
style: TextStyle(color: Colors.black54),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
onPressed: () {},
padding: EdgeInsets.zero,
icon: SvgPicture.asset(
"assets/icons/email_box.svg",
height: 64,
width: 64,
),
),
IconButton(
onPressed: () {},
padding: EdgeInsets.zero,
icon: SvgPicture.asset(
"assets/icons/apple_box.svg",
height: 64,
width: 64,
),
),
IconButton(
onPressed: () {},
padding: EdgeInsets.zero,
icon: SvgPicture.asset(
"assets/icons/google_box.svg",
height: 64,
width: 64,
),
),
],
),
],
),
),
const Positioned(
left: 0,
right: 0,
bottom: -48,
child: CircleAvatar(
radius: 16,
backgroundColor: Colors.white,
child: Icon(
Icons.close,
size: 20,
color: Colors.black,
),
),
)
],
),
),
),
);
},
transitionBuilder: (_, anim, __, child) {
Tween<Offset> tween;
// if (anim.status == AnimationStatus.reverse) {
// tween = Tween(begin: const Offset(0, 1), end: Offset.zero);
// } else {
// tween = Tween(begin: const Offset(0, -1), end: Offset.zero);
// }
tween = Tween(begin: const Offset(0, -1), end: Offset.zero);
return SlideTransition(
position: tween.animate(
CurvedAnimation(parent: anim, curve: Curves.easeInOut),
),
// child: FadeTransition(
// opacity: anim,
// child: child,
// ),
child: child,
);
},
).then(onValue);
}

View File

@@ -0,0 +1,225 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:rive/rive.dart';
import 'package:motula_translate_app/screens/entryPoint/entry_point.dart';
class SignInForm extends StatefulWidget {
const SignInForm({
Key? key,
}) : super(key: key);
@override
State<SignInForm> createState() => _SignInFormState();
}
class _SignInFormState extends State<SignInForm> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
bool isShowLoading = false;
bool isShowConfetti = false;
late SMITrigger error;
late SMITrigger success;
late SMITrigger reset;
late SMITrigger confetti;
void _onCheckRiveInit(Artboard artboard) {
StateMachineController? controller =
StateMachineController.fromArtboard(artboard, 'State Machine 1');
artboard.addController(controller!);
error = controller.findInput<bool>('Error') as SMITrigger;
success = controller.findInput<bool>('Check') as SMITrigger;
reset = controller.findInput<bool>('Reset') as SMITrigger;
}
void _onConfettiRiveInit(Artboard artboard) {
StateMachineController? controller =
StateMachineController.fromArtboard(artboard, "State Machine 1");
artboard.addController(controller!);
confetti = controller.findInput<bool>("Trigger explosion") as SMITrigger;
}
void singIn(BuildContext context) {
// confetti.fire();
setState(() {
isShowConfetti = true;
isShowLoading = true;
});
Future.delayed(
const Duration(seconds: 1),
() {
if (_formKey.currentState!.validate()) {
success.fire();
Future.delayed(
const Duration(seconds: 2),
() {
setState(() {
isShowLoading = false;
});
confetti.fire();
// Navigate & hide confetti
Future.delayed(const Duration(seconds: 1), () {
// Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const EntryPoint(),
),
);
});
},
);
} else {
error.fire();
Future.delayed(
const Duration(seconds: 2),
() {
setState(() {
isShowLoading = false;
});
reset.fire();
},
);
}
},
);
}
@override
Widget build(BuildContext context) {
return Stack(
children: [
Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Email",
style: TextStyle(
color: Colors.black54,
),
),
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 16),
child: TextFormField(
validator: (value) {
if (value!.isEmpty) {
return "";
}
return null;
},
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: SvgPicture.asset("assets/icons/email.svg"),
),
),
),
),
const Text(
"Password",
style: TextStyle(
color: Colors.black54,
),
),
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 16),
child: TextFormField(
obscureText: true,
validator: (value) {
if (value!.isEmpty) {
return "";
}
return null;
},
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: SvgPicture.asset("assets/icons/password.svg"),
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 24),
child: ElevatedButton.icon(
onPressed: () {
singIn(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFF77D8E),
minimumSize: const Size(double.infinity, 56),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(25),
bottomRight: Radius.circular(25),
bottomLeft: Radius.circular(25),
),
),
),
icon: const Icon(
CupertinoIcons.arrow_right,
color: Color(0xFFFE0037),
),
label: const Text("Sign In"),
),
),
],
),
),
isShowLoading
? CustomPositioned(
child: RiveAnimation.asset(
'assets/RiveAssets/check.riv',
fit: BoxFit.cover,
onInit: _onCheckRiveInit,
),
)
: const SizedBox(),
isShowConfetti
? CustomPositioned(
scale: 6,
child: RiveAnimation.asset(
"assets/RiveAssets/confetti.riv",
onInit: _onConfettiRiveInit,
fit: BoxFit.cover,
),
)
: const SizedBox(),
],
);
}
}
class CustomPositioned extends StatelessWidget {
const CustomPositioned({super.key, this.scale = 1, required this.child});
final double scale;
final Widget child;
@override
Widget build(BuildContext context) {
return Positioned.fill(
child: Column(
children: [
const Spacer(),
SizedBox(
height: 100,
width: 100,
child: Transform.scale(
scale: scale,
child: child,
),
),
const Spacer(flex: 2),
],
),
);
}
}

View File

@@ -0,0 +1,132 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
import 'components/animated_btn.dart';
import 'components/sign_in_dialog.dart';
class OnbodingScreen extends StatefulWidget {
const OnbodingScreen({super.key});
@override
State<OnbodingScreen> createState() => _OnbodingScreenState();
}
class _OnbodingScreenState extends State<OnbodingScreen> {
late RiveAnimationController _btnAnimationController;
bool isShowSignInDialog = false;
@override
void initState() {
_btnAnimationController = OneShotAnimation(
"active",
autoplay: false,
);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Positioned(
width: MediaQuery.of(context).size.width * 1.7,
left: 100,
bottom: 100,
child: Image.asset(
"assets/Backgrounds/Spline.png",
),
),
Positioned.fill(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),
child: const SizedBox(),
),
),
const RiveAnimation.asset(
"assets/RiveAssets/shapes.riv",
),
Positioned.fill(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 30, sigmaY: 30),
child: const SizedBox(),
),
),
AnimatedPositioned(
top: isShowSignInDialog ? -50 : 0,
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
duration: const Duration(milliseconds: 260),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Spacer(),
const SizedBox(
width: 260,
child: Column(
children: [
Text(
"Learn design & code",
style: TextStyle(
fontSize: 60,
fontWeight: FontWeight.w700,
fontFamily: "Poppins",
height: 1.2,
),
),
SizedBox(height: 16),
Text(
"Dont skip design. Learn design and code, by building real apps with Flutter and Swift. Complete courses about the best tools.",
),
],
),
),
const Spacer(flex: 2),
AnimatedBtn(
btnAnimationController: _btnAnimationController,
press: () {
_btnAnimationController.isActive = true;
Future.delayed(
const Duration(milliseconds: 800),
() {
setState(() {
isShowSignInDialog = true;
});
showCustomDialog(
context,
onValue: (_) {},
);
// showCustomDialog(
// context,
// onValue: (_) {
// setState(() {
// isShowSignInDialog = false;
// });
// },
// );
},
);
},
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 24),
child: Text(
"Purchase includes access to 30+ courses, 240+ premium tutorials, 120+ hours of videos, source files and certificates."),
)
],
),
),
),
),
],
),
);
}
}