splash_page.dart
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2019 The FlutterCandies author. All rights reserved.
// Use of this source code is governed by an Apache license that can be found
// in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import '../main.dart';
import 'home_page.dart';
class SplashPage extends StatefulWidget {
const SplashPage({super.key});
@override
State<SplashPage> createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage> {
@override
void initState() {
super.initState();
init();
}
Future<void> init() async {
try {
final PackageInfo info = await PackageInfo.fromPlatform();
packageVersion = info.version;
} catch (_) {}
await Future<void>.delayed(const Duration(seconds: 1));
if (mounted) {
Navigator.maybeOf(context)?.pushReplacement(
PageRouteBuilder<void>(
pageBuilder: (_, __, ___) => const HomePage(),
transitionsBuilder: (_, Animation<double> a, __, Widget child) {
return FadeTransition(opacity: a, child: child);
},
transitionDuration: const Duration(seconds: 1),
),
);
}
}
@override
Widget build(BuildContext context) {
return Material(
color: Theme.of(context).canvasColor,
child: Center(
child: Hero(
tag: 'LOGO',
child: Image.asset('assets/flutter_candies_logo.png', width: 150.0),
),
),
);
}
}