From e7a8d0e1d5a6a82cc9f9c14aee5827994a526395 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Sat, 17 Dec 2022 21:05:50 +0300 Subject: [PATCH] Added version label --- lib/l10n/intl_en.arb | 13 +++- lib/main.dart | 1 + lib/main_mock.dart | 1 + .../settings/components/version_label.dart | 27 ++++++++ lib/screens/settings/settings_screen.dart | 69 +++++++++++-------- pubspec.yaml | 3 +- 6 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 lib/screens/settings/components/version_label.dart diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 698d54e..d3adaae 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -24,5 +24,16 @@ "chooseTheme": "Choose theme", "themeLight": "Light", "themeDark": "Dark", - "themeSystemDefault": "System default" + "themeSystemDefault": "System default", + "version": "Version: {version} ({buildNumber})", + "@version": { + "placeholders": { + "version": { + "type": "String" + }, + "buildNumber": { + "type": "String" + } + } + } } \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 3abe576..49a2651 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,5 +4,6 @@ import 'package:lightmeter/data/ev_source/ev_source_type.dart'; import 'application.dart'; void main() { + WidgetsFlutterBinding.ensureInitialized(); runApp(const Application(EvSourceType.camera)); } diff --git a/lib/main_mock.dart b/lib/main_mock.dart index 15b1225..9c85198 100644 --- a/lib/main_mock.dart +++ b/lib/main_mock.dart @@ -4,5 +4,6 @@ import 'package:lightmeter/data/ev_source/ev_source_type.dart'; import 'application.dart'; void main() { + WidgetsFlutterBinding.ensureInitialized(); runApp(const Application(EvSourceType.mock)); } \ No newline at end of file diff --git a/lib/screens/settings/components/version_label.dart b/lib/screens/settings/components/version_label.dart new file mode 100644 index 0000000..4491cee --- /dev/null +++ b/lib/screens/settings/components/version_label.dart @@ -0,0 +1,27 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/generated/l10n.dart'; +import 'package:package_info_plus/package_info_plus.dart'; + +class VersionLabel extends StatelessWidget { + const VersionLabel({super.key}); + + @override + Widget build(BuildContext context) { + return FutureBuilder( + future: PackageInfo.fromPlatform(), + builder: (context, snapshot) { + if (snapshot.data != null) { + final version = snapshot.data!.version; + final buildNumber = snapshot.data!.buildNumber; + return Center( + child: Text( + S.of(context).version(version, buildNumber), + style: Theme.of(context).textTheme.bodySmall, + ), + ); + } + return const SizedBox.shrink(); + }, + ); + } +} diff --git a/lib/screens/settings/settings_screen.dart b/lib/screens/settings/settings_screen.dart index 715a0e5..579524f 100644 --- a/lib/screens/settings/settings_screen.dart +++ b/lib/screens/settings/settings_screen.dart @@ -4,6 +4,7 @@ import 'package:lightmeter/res/dimens.dart'; import 'components/fractional_stops_tile.dart'; import 'components/theme_type_tile.dart'; +import 'components/version_label.dart'; class SettingsScreen extends StatelessWidget { const SettingsScreen({super.key}); @@ -12,38 +13,48 @@ class SettingsScreen extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( backgroundColor: Theme.of(context).colorScheme.surface, - body: CustomScrollView( - slivers: [ - SliverAppBar( - pinned: true, - automaticallyImplyLeading: false, - expandedHeight: Dimens.grid168, - flexibleSpace: FlexibleSpaceBar( - centerTitle: false, - titlePadding: const EdgeInsets.all(Dimens.paddingM), - title: Text( - S.of(context).settings, - style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontSize: 24), + body: SafeArea( + top: false, + child: CustomScrollView( + slivers: [ + SliverAppBar( + pinned: true, + automaticallyImplyLeading: false, + expandedHeight: Dimens.grid168, + flexibleSpace: FlexibleSpaceBar( + centerTitle: false, + titlePadding: const EdgeInsets.all(Dimens.paddingM), + title: Text( + S.of(context).settings, + style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontSize: 24), + ), ), - ), - actions: [ - IconButton( - onPressed: Navigator.of(context).pop, - icon: const Icon(Icons.close), - ), - ], - ), - SliverList( - delegate: SliverChildListDelegate( - [ - const StopTypeListTile(), - // const CaffeineListTile(), - // const HapticsListTile(), - const ThemeTypeListTile(), + actions: [ + IconButton( + onPressed: Navigator.of(context).pop, + icon: const Icon(Icons.close), + ), ], ), - ), - ], + SliverList( + delegate: SliverChildListDelegate( + [ + const StopTypeListTile(), + // const CaffeineListTile(), + // const HapticsListTile(), + const ThemeTypeListTile(), + ], + ), + ), + SliverFillRemaining( + hasScrollBody: false, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: const [VersionLabel()], + ), + ), + ], + ), ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index 76e4d53..b88c655 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: lightmeter description: A new Flutter project. publish_to: "none" -version: 1.0.0+1 +version: 0.1.0+1 environment: sdk: ">=2.18.0 <3.0.0" @@ -17,6 +17,7 @@ dependencies: intl: 0.17.0 intl_utils: 2.8.1 material_color_utilities: ^0.2.0 + package_info_plus: 3.0.2 permission_handler: 10.2.0 provider: ^6.0.4 shared_preferences: 2.0.15