From ad4436aa71ab72b4416df652544666ff55b1c8c6 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Sat, 3 May 2025 19:06:55 +0200 Subject: [PATCH] Added: show version in user settings, CI: generated releases --- .gitea/workflows/build.yaml | 55 +++++++++++++ lib/screens/user_settings.dart | 25 +++++- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 79 ++++++++++++++++++- pubspec.yaml | 6 +- 5 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 .gitea/workflows/build.yaml diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..7d5aef9 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,55 @@ +name: Build and Release APK + +on: + push: + tags: + - "v*.*.*" # Runs only when a version tag is pushed + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: "3.29.3" + + - name: Install dependencies + run: flutter pub get + + - name: Build APK + run: flutter build apk --release + + - name: Create Gitea release + env: + TOKEN_GITEA: ${{ secrets.TOKEN_GITEA }} + TAG_NAME: ${{ github.ref_name }} + run: | + curl -X POST https://git.filiprojek.cz/api/v1/repos/fr/android_fuelstats/releases \ + -H "Authorization: token $TOKEN_GITEA" \ + -H "Content-Type: application/json" \ + -d '{ + "tag_name": "'"$TAG_NAME"'", + "name": "'"$TAG_NAME"'", + "body": "Automated release for version '"$TAG_NAME"'", + "draft": false, + "prerelease": false + }' + + - name: Upload APK to release + env: + TOKEN_GITEA: ${{ secrets.TOKEN_GITEA }} + TAG_NAME: ${{ github.ref_name }} + run: | + # Get release ID + RELEASE_ID=$(curl -s -H "Authorization: token $TOKEN_GITEA" \ + https://git.filiprojek.cz/api/v1/repos/fr/android_fuelstats/releases/tags/$TAG_NAME \ + | jq -r '.id') + + curl -X POST \ + -H "Authorization: token $TOKEN_GITEA" \ + -F "attachment=@build/app/outputs/flutter-apk/app-release.apk" \ + https://git.filiprojek.cz/api/v1/repos/fr/android_fuelstats/releases/$RELEASE_ID/assets diff --git a/lib/screens/user_settings.dart b/lib/screens/user_settings.dart index 9c57498..e568ffe 100644 --- a/lib/screens/user_settings.dart +++ b/lib/screens/user_settings.dart @@ -1,18 +1,27 @@ import 'package:flutter/material.dart'; +import 'package:package_info_plus/package_info_plus.dart'; class UserSettingsScreen extends StatelessWidget { + Future _getVersion() async { + final info = await PackageInfo.fromPlatform(); + //return 'Version: ${info.version}+${info.buildNumber}'; + return 'Version: ${info.version}'; + } + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('User settings')), body: Center( child: Column( - spacing: 20.0, + mainAxisSize: MainAxisSize.min, children: [ const Text( "Test User", style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold), ), + + SizedBox(height: 20), ElevatedButton.icon( onPressed: () { // TODO: Add sign-out logic here @@ -24,6 +33,20 @@ class UserSettingsScreen extends StatelessWidget { foregroundColor: Colors.white, ), ), + SizedBox(height: 8), + FutureBuilder( + future: _getVersion(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + return Text( + snapshot.data ?? '', + style: TextStyle(color: Colors.grey), + ); + } else { + return SizedBox.shrink(); + } + }, + ), ], ), ), diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index cccf817..a8b637f 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,8 @@ import FlutterMacOS import Foundation +import package_info_plus func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index d993b91..0225765 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -57,6 +57,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.2" + ffi: + dependency: transitive + description: + name: ffi + sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418" + url: "https://pub.dev" + source: hosted + version: "2.1.4" flutter: dependency: "direct main" description: flutter @@ -75,6 +83,27 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + http: + dependency: transitive + description: + name: http + sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f + url: "https://pub.dev" + source: hosted + version: "1.3.0" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" + url: "https://pub.dev" + source: hosted + version: "4.1.2" leak_tracker: dependency: transitive description: @@ -131,6 +160,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.16.0" + package_info_plus: + dependency: "direct main" + description: + name: package_info_plus + sha256: "7976bfe4c583170d6cdc7077e3237560b364149fcd268b5f53d95a991963b191" + url: "https://pub.dev" + source: hosted + version: "8.3.0" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + sha256: "6c935fb612dff8e3cc9632c2b301720c77450a126114126ffaafe28d2e87956c" + url: "https://pub.dev" + source: hosted + version: "3.2.0" path: dependency: transitive description: @@ -139,6 +184,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.9.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" + url: "https://pub.dev" + source: hosted + version: "2.1.8" sky_engine: dependency: transitive description: flutter @@ -192,6 +245,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.4" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" vector_math: dependency: transitive description: @@ -208,6 +269,22 @@ packages: url: "https://pub.dev" source: hosted version: "14.3.1" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + win32: + dependency: transitive + description: + name: win32 + sha256: dc6ecaa00a7c708e5b4d10ee7bec8c270e9276dfcab1783f57e9962d7884305f + url: "https://pub.dev" + source: hosted + version: "5.12.0" sdks: dart: ">=3.7.2 <4.0.0" - flutter: ">=3.18.0-18.0.pre.54" + flutter: ">=3.19.0" diff --git a/pubspec.yaml b/pubspec.yaml index 3893440..6db3ee3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: fuelstats description: "A new Flutter project." # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+1 +version: 0.1.1 environment: sdk: ^3.7.2 @@ -34,6 +34,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 + package_info_plus: ^8.3.0 dev_dependencies: flutter_test: @@ -51,7 +52,6 @@ dev_dependencies: # The following section is specific to Flutter packages. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class.