Mostrar la versión en la app
This commit is contained in:
@@ -1,5 +1,37 @@
|
|||||||
package es.freetimelab.farolero
|
package es.freetimelab.farolero
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
|
||||||
class MainActivity: FlutterActivity()
|
class MainActivity: FlutterActivity() {
|
||||||
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
|
super.configureFlutterEngine(flutterEngine)
|
||||||
|
|
||||||
|
MethodChannel(
|
||||||
|
flutterEngine.dartExecutor.binaryMessenger,
|
||||||
|
"farolero/app_info"
|
||||||
|
).setMethodCallHandler { call, result ->
|
||||||
|
if (call.method != "getAppVersion") {
|
||||||
|
result.notImplemented()
|
||||||
|
return@setMethodCallHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
val info = packageManager.getPackageInfo(packageName, 0)
|
||||||
|
val versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
info.longVersionCode
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
info.versionCode.toLong()
|
||||||
|
}
|
||||||
|
|
||||||
|
result.success(
|
||||||
|
mapOf(
|
||||||
|
"versionName" to (info.versionName ?: ""),
|
||||||
|
"versionCode" to versionCode,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:farolero/l10n/generated/app_localizations.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../servicios/servicio_idioma.dart';
|
import '../servicios/servicio_idioma.dart';
|
||||||
import '../servicios/servicio_perfil_usuario.dart';
|
import '../servicios/servicio_perfil_usuario.dart';
|
||||||
|
import '../servicios/servicio_version_app.dart';
|
||||||
import '../tema/componentes_farolero.dart';
|
import '../tema/componentes_farolero.dart';
|
||||||
import '../tema/tema_app.dart';
|
import '../tema/tema_app.dart';
|
||||||
|
|
||||||
@@ -16,6 +17,13 @@ class PantallaAjustes extends StatefulWidget {
|
|||||||
class _PantallaAjustesState extends State<PantallaAjustes> {
|
class _PantallaAjustesState extends State<PantallaAjustes> {
|
||||||
double _volumen = 0.7;
|
double _volumen = 0.7;
|
||||||
bool _vibracion = true;
|
bool _vibracion = true;
|
||||||
|
late final Future<String> _versionApp;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_versionApp = ServicioVersionApp.obtenerVersion();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -129,18 +137,29 @@ class _PantallaAjustesState extends State<PantallaAjustes> {
|
|||||||
Text(l10n.about,
|
Text(l10n.about,
|
||||||
style: Theme.of(context).textTheme.titleLarge),
|
style: Theme.of(context).textTheme.titleLarge),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_filaInfo(context, l10n.version, '1.0.0'),
|
FutureBuilder<String>(
|
||||||
|
future: _versionApp,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
return _filaInfo(
|
||||||
|
context,
|
||||||
|
l10n.version,
|
||||||
|
snapshot.data ?? '-',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
_filaInfo(context, l10n.developer, 'FreeTTimeLab'),
|
_filaInfo(context, l10n.developer, 'FreeTTimeLab'),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: OutlinedButton(
|
child: OutlinedButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
|
final version = await _versionApp;
|
||||||
|
if (!context.mounted) return;
|
||||||
showLicensePage(
|
showLicensePage(
|
||||||
context: context,
|
context: context,
|
||||||
applicationName: 'Farolero',
|
applicationName: 'Farolero',
|
||||||
applicationVersion: '1.0.0',
|
applicationVersion: version,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Text(l10n.licenses),
|
child: Text(l10n.licenses),
|
||||||
|
|||||||
29
lib/servicios/servicio_version_app.dart
Normal file
29
lib/servicios/servicio_version_app.dart
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
class ServicioVersionApp {
|
||||||
|
static const _channel = MethodChannel('farolero/app_info');
|
||||||
|
|
||||||
|
static Future<String> obtenerVersion() async {
|
||||||
|
final Map<String, dynamic>? info;
|
||||||
|
try {
|
||||||
|
info = await _channel.invokeMapMethod<String, dynamic>(
|
||||||
|
'getAppVersion',
|
||||||
|
);
|
||||||
|
} on PlatformException {
|
||||||
|
return '-';
|
||||||
|
} on MissingPluginException {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
final versionName = info?['versionName']?.toString();
|
||||||
|
final versionCode = info?['versionCode']?.toString();
|
||||||
|
|
||||||
|
if (versionName == null || versionName.isEmpty) {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
if (versionCode == null || versionCode.isEmpty) {
|
||||||
|
return versionName;
|
||||||
|
}
|
||||||
|
return '$versionName+$versionCode';
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user