splash_screen.dart
Purpose
This file defines the SplashScreen widget, a simple introductory screen shown during app startup. It retrieves the app version and displays the logo and version text.
Imports
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:package_info_plus/package_info_plus.dart';
Flutter Core: UI and layout.
Google Fonts: Custom text styling.
Package Info Plus: Fetches the app version dynamically.
SplashScreen Widget
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
A StatefulWidget that holds dynamic UI logic, such as retrieving the version at runtime.
_SplashScreenState Class
Variables
String _version = '';
Stores the version number fetched from the platform.
initState()
@override
void initState() {
super.initState();
_loadVersion();
}
Initializes the widget and calls the method to load the app version.
_loadVersion()
Future<void> _loadVersion() async {
final packageInfo = await PackageInfo.fromPlatform();
setState(() {
_version = packageInfo.version;
});
}
Uses PackageInfo.fromPlatform() to retrieve the version and updates the UI.
build()
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
The layout is composed of:
A column with a logo (
Image.asset)Two
Textwidgets: one for app name and one for versionUses
GoogleFonts.robotofor styling
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/logo.png', width: size.width * 0.4),
Text('HealthyWear', style: GoogleFonts.roboto(...)),
Text('v$_version', style: GoogleFonts.roboto(...)),
],
),
Ensure logo.png is present in assets/ and listed in pubspec.yaml.
Dependencies
assets/logo.png— image must exist in asset bundle.Declared in
pubspec.yamlunderassets:section.