import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';

/// Ein Widget mit der aktuellen Versionsnummer
class VersionNumber extends StatefulWidget {
  /// Erstellt eine neue Instanz dieser Klasse
  const VersionNumber({super.key});

  @override
  State<StatefulWidget> createState() => _VersionNumber();
}

class _VersionNumber extends State<VersionNumber> {
  @override
  Widget build(final BuildContext context) => Align(
    alignment: Alignment.bottomLeft,
    child: FutureBuilder(
      future: PackageInfo.fromPlatform(),
      builder:
          (
            final BuildContext context,
            final AsyncSnapshot<PackageInfo> snapshot,
          ) {
            final ThemeData theme = Theme.of(context);

            if (snapshot.hasData) {
              return Text(
                '${snapshot.data?.version}+${snapshot.data?.buildNumber}',
                style: theme.textTheme.bodySmall?.copyWith(
                  color: theme.colorScheme.onSurface.withAlpha(
                    (0.6 * 255).round(),
                  ),
                ),
              );
            } else {
              return const CircularProgressIndicator();
            }
          },
    ),
  );
}
