import 'package:flutter/material.dart';
class PlayPauseButton extends StatefulWidget {
final bool isPlaying;
final VoidCallback onPressed;
PlayPauseButton({required this.isPlaying, required this.onPressed});
@override
_PlayPauseButtonState createState() => _PlayPauseButtonState();
}
class _PlayPauseButtonState extends State<PlayPauseButton> with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> _animation;
@override
void initState() {
super.initState();
_animationController = AnimationController(
duration: Duration(milliseconds: 300),
vsync: this,
);
_animation = Tween<double>(begin: 0.0, end: 1.0).animate(_animationController);
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
void didUpdateWidget(covariant PlayPauseButton oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isPlaying) {
_animationController.forward();
} else {
_animationController.reverse();
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onPressed,
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.transparent,
),
child: Stack(
children: [
Center(
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black,
),
),
),
Center(
child: ScaleTransition(
scale: _animation,
child: Icon(
widget.isPlaying ? Icons.pause : Icons.play_arrow,
size: 30,
color: Colors.white,
),
),
),
],
),
),
);
}
}
FutureBuilder(
future: Future<void>.delayed(const Duration(seconds: 1)),
builder: (context, snapshot) {
return SizedBox();
},
),
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool? isLoggedIn;
Future<void> checkLoggedIn() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
bool? isLoggedIn = prefs.getBool('isLogin');
this.setState(() {
isLoggedIn = isLoggedIn;
});
}
@override
void initState() {
super.initState();
Future.microtask(() async => await checkLoggedIn());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MY APP',
debugShowCheckedModeBanner: false,
scrollBehavior: MyCustomScrollBehavior(),
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: SingleChildScrollView(child:
isLoggedIn != null?
isLoggedIn!
? Main()
: Login()
: OpenScreen()
),
),
);
}
}