splash_page.dart 1.5 KB

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