Skip to content

Commit fdee379

Browse files
committed
Added Splash screen with animation on OMDB
1 parent ce3e230 commit fdee379

File tree

10 files changed

+179
-6
lines changed

10 files changed

+179
-6
lines changed

music_player/lib/features/player/data/data_source/local/local_data_source.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ class PlayerLocalDataSourceImpl extends PlayerLocalDataSource {
2525
Future<void> updateSongEntry(RecentSongModel songEntity) async {
2626
final response = LocalDatabase.getStringList(key);
2727
List<RecentSongModel> recentSong = [];
28+
bool isExists = false;
2829
for (var element in response) {
2930
final song = RecentSongModel.fromJson(element);
3031
if (song.songEntity.id == songEntity.songEntity.id) {
32+
isExists = true;
3133
recentSong.add(songEntity);
3234
} else {
3335
recentSong.add(song);
3436
}
3537
}
36-
if (response.isEmpty) {
38+
if (!isExists) {
3739
recentSong.add(songEntity);
3840
}
3941
await LocalDatabase.setStringList(

omdb/android/app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<uses-permission android:name="android.permission.INTERNET"/>
23
<application
34
android:label="omdb"
45
android:name="${applicationName}"

omdb/assets/json/splash-animation.json

+1
Large diffs are not rendered by default.

omdb/lib/core/assets/app_assets.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
class AppAssets {
22
static const String noImageSvg = "assets/svg/no-image.svg";
3+
static const String splashAnimationLottie =
4+
"assets/json/splash-animation.json";
35
}

omdb/lib/core/routes/routes.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import 'package:omdb/screens/home/presentation/home.dart';
44
import 'package:omdb/screens/movie/domain/entity/collection.dart';
55
import 'package:omdb/screens/movie/presentation/bloc/movie_collection_bloc.dart';
66
import 'package:omdb/screens/movie/presentation/movie_details.dart';
7+
import 'package:omdb/screens/splash/presentation/splash.dart';
78
import 'package:omdb/sl.dart';
89

910
class AppRoutes {
10-
static const String home = '/';
11+
static const String splash = '/';
12+
static const String home = '/home';
1113
static const String movieDetails = '/movie/details';
1214

1315
static Route onGenerateRoute(RouteSettings settings) {
@@ -24,11 +26,13 @@ class AppRoutes {
2426
collectionEnity: collection,
2527
),
2628
);
27-
default:
29+
case home:
2830
child = BlocProvider(
2931
create: (context) => MovieCollectionBloc(sl(), sl()),
3032
child: const HomeScreen(),
3133
);
34+
default:
35+
child = const SplashScreen();
3236
}
3337
return MaterialPageRoute(builder: (context) => child);
3438
}

omdb/lib/core/utils/network/network.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import 'package:http/http.dart' as http;
44
import 'package:omdb/core/utils/constants/constants.dart';
55

66
class NetworkHelper {
7-
Future<http.Response> get({required String query}) {
7+
Future<http.Response> get({required String query}) async {
88
try {
9-
return http.get(
9+
final response = await http.get(
1010
Uri.parse(
1111
"${AppConstants.baseUrl}/?apikey=${AppConstants.apiKey}&$query"),
1212
);
13+
return response;
1314
} catch (e) {
1415
rethrow;
1516
}

omdb/lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MyApp extends StatelessWidget {
2525
),
2626
debugShowCheckedModeBanner: false,
2727
onGenerateRoute: AppRoutes.onGenerateRoute,
28-
initialRoute: AppRoutes.home,
28+
initialRoute: AppRoutes.splash,
2929
);
3030
}
3131
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import 'dart:async';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:lottie/lottie.dart';
5+
import 'package:omdb/core/assets/app_assets.dart';
6+
import 'package:omdb/core/routes/routes.dart';
7+
8+
class SplashScreen extends StatefulWidget {
9+
const SplashScreen({super.key});
10+
11+
@override
12+
State<SplashScreen> createState() => _SplashScreenState();
13+
}
14+
15+
class _SplashScreenState extends State<SplashScreen>
16+
with TickerProviderStateMixin {
17+
late AnimationController animationController;
18+
late AnimationController fadeController;
19+
late Animation<double> tweenAnimation;
20+
late Animation<double> fadeAnimation;
21+
bool startAlignmentAnimation = false;
22+
23+
@override
24+
void initState() {
25+
animationController = AnimationController(
26+
vsync: this,
27+
duration: const Duration(seconds: 1),
28+
);
29+
fadeController = AnimationController(
30+
vsync: this,
31+
duration: const Duration(milliseconds: 500),
32+
);
33+
tweenAnimation = Tween<double>(begin: 0, end: 38).animate(
34+
CurvedAnimation(parent: animationController, curve: Curves.bounceOut))
35+
..addListener(() {
36+
if (animationController.isCompleted) {
37+
Timer(const Duration(seconds: 1), () {
38+
fadeController.forward();
39+
});
40+
}
41+
setState(() {});
42+
});
43+
fadeAnimation = Tween<double>(begin: 1, end: 0)
44+
.animate(CurvedAnimation(parent: fadeController, curve: Curves.easeIn))
45+
..addListener(() {
46+
if (fadeController.isCompleted) {
47+
Navigator.pushReplacementNamed(context, AppRoutes.home);
48+
}
49+
setState(() {});
50+
});
51+
animationController.forward();
52+
Timer(const Duration(milliseconds: 500), () {
53+
startAlignmentAnimation = true;
54+
setState(() {});
55+
});
56+
super.initState();
57+
}
58+
59+
@override
60+
Widget build(BuildContext context) {
61+
return Scaffold(
62+
body: Opacity(
63+
opacity: fadeAnimation.value,
64+
child: Center(
65+
child: Column(
66+
mainAxisAlignment: MainAxisAlignment.center,
67+
crossAxisAlignment: CrossAxisAlignment.center,
68+
children: [
69+
Lottie.asset(
70+
AppAssets.splashAnimationLottie,
71+
),
72+
Row(
73+
children: [
74+
Expanded(
75+
child: Align(
76+
alignment: Alignment.centerRight,
77+
child: Text(
78+
"OMDB ",
79+
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
80+
fontWeight: FontWeight.w700,
81+
fontSize: tweenAnimation.value,
82+
color: Colors.yellow[700],
83+
),
84+
),
85+
),
86+
),
87+
Expanded(
88+
child: AnimatedAlign(
89+
alignment: !startAlignmentAnimation
90+
? Alignment.centerRight
91+
: Alignment.centerLeft,
92+
duration: const Duration(milliseconds: 500),
93+
curve: Curves.easeInOutExpo,
94+
child: Text(
95+
"Movies",
96+
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
97+
fontWeight: FontWeight.w700,
98+
fontSize: 38,
99+
color: Colors.grey[700],
100+
),
101+
),
102+
),
103+
),
104+
],
105+
)
106+
],
107+
),
108+
),
109+
),
110+
);
111+
}
112+
}

omdb/pubspec.lock

+48
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Generated by pub
22
# See https://dart.dev/tools/pub/glossary#lockfile
33
packages:
4+
archive:
5+
dependency: transitive
6+
description:
7+
name: archive
8+
sha256: "22600aa1e926be775fa5fe7e6894e7fb3df9efda8891c73f70fb3262399a432d"
9+
url: "https://pub.dev"
10+
source: hosted
11+
version: "3.4.10"
412
args:
513
dependency: transitive
614
description:
@@ -57,6 +65,22 @@ packages:
5765
url: "https://pub.dev"
5866
source: hosted
5967
version: "1.18.0"
68+
convert:
69+
dependency: transitive
70+
description:
71+
name: convert
72+
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
73+
url: "https://pub.dev"
74+
source: hosted
75+
version: "3.1.1"
76+
crypto:
77+
dependency: transitive
78+
description:
79+
name: crypto
80+
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
81+
url: "https://pub.dev"
82+
source: hosted
83+
version: "3.0.3"
6084
cupertino_icons:
6185
dependency: "direct main"
6286
description:
@@ -160,6 +184,14 @@ packages:
160184
url: "https://pub.dev"
161185
source: hosted
162186
version: "4.0.2"
187+
js:
188+
dependency: transitive
189+
description:
190+
name: js
191+
sha256: "4186c61b32f99e60f011f7160e32c89a758ae9b1d0c6d28e2c02ef0382300e2b"
192+
url: "https://pub.dev"
193+
source: hosted
194+
version: "0.7.0"
163195
lints:
164196
dependency: transitive
165197
description:
@@ -168,6 +200,14 @@ packages:
168200
url: "https://pub.dev"
169201
source: hosted
170202
version: "2.1.1"
203+
lottie:
204+
dependency: "direct main"
205+
description:
206+
name: lottie
207+
sha256: "1f0ce68112072d66ea271a9841994fa8d16442e23d8cf8996c9fa74174e58b4e"
208+
url: "https://pub.dev"
209+
source: hosted
210+
version: "3.0.0"
171211
matcher:
172212
dependency: transitive
173213
description:
@@ -272,6 +312,14 @@ packages:
272312
url: "https://pub.dev"
273313
source: hosted
274314
version: "2.1.8"
315+
pointycastle:
316+
dependency: transitive
317+
description:
318+
name: pointycastle
319+
sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29"
320+
url: "https://pub.dev"
321+
source: hosted
322+
version: "3.7.4"
275323
provider:
276324
dependency: transitive
277325
description:

omdb/pubspec.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies:
3636
flutter_svg: ^2.0.9
3737
get_it: ^7.6.7
3838
http: ^1.2.0
39+
lottie: ^3.0.0
3940
shared_preferences: ^2.2.2
4041

4142
dev_dependencies:
@@ -55,6 +56,7 @@ flutter:
5556
# To add assets to your application, add an assets section, like this:
5657
assets:
5758
- assets/svg/
59+
- assets/json/
5860
# - images/a_dot_ham.jpeg
5961
# An image asset can refer to one or more resolution-specific "variants", see
6062
# https://flutter.dev/assets-and-images/#resolution-aware

0 commit comments

Comments
 (0)