92 lines
2.4 KiB
Dart
92 lines
2.4 KiB
Dart
import 'dart:async';
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'package:audio_service/audio_service.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'app.dart';
|
|
import 'servicios/servicio_audio.dart';
|
|
|
|
const _anchoMinimoLandscape = 600.0;
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await _aplicarPoliticaOrientacion();
|
|
|
|
final handler = await AudioService.init(
|
|
builder: () => PluriWaveAudioHandler(),
|
|
config: const AudioServiceConfig(
|
|
androidNotificationChannelId: 'es.freetimelab.pluriwave.audio',
|
|
androidNotificationChannelName: 'PluriWave Radio',
|
|
androidNotificationOngoing: true,
|
|
androidStopForegroundOnPause: true,
|
|
notificationColor: Color(0xFF6750A4),
|
|
),
|
|
);
|
|
registrarHandler(handler);
|
|
|
|
runApp(const _OrientacionResponsiveApp(child: PluriWaveApp()));
|
|
}
|
|
|
|
Future<void> _aplicarPoliticaOrientacion([ui.Display? display]) async {
|
|
final vista =
|
|
WidgetsBinding.instance.platformDispatcher.views.isNotEmpty
|
|
? WidgetsBinding.instance.platformDispatcher.views.first
|
|
: null;
|
|
final displayActivo = display ?? vista?.display;
|
|
if (displayActivo == null) return;
|
|
|
|
final anchoLogico =
|
|
displayActivo.size.width / displayActivo.devicePixelRatio;
|
|
if (anchoLogico < _anchoMinimoLandscape) {
|
|
await SystemChrome.setPreferredOrientations([
|
|
DeviceOrientation.portraitUp,
|
|
]);
|
|
return;
|
|
}
|
|
|
|
await SystemChrome.setPreferredOrientations(DeviceOrientation.values);
|
|
}
|
|
|
|
class _OrientacionResponsiveApp extends StatefulWidget {
|
|
const _OrientacionResponsiveApp({required this.child});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
State<_OrientacionResponsiveApp> createState() =>
|
|
_OrientacionResponsiveAppState();
|
|
}
|
|
|
|
class _OrientacionResponsiveAppState extends State<_OrientacionResponsiveApp>
|
|
with WidgetsBindingObserver {
|
|
ui.Display? _display;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addObserver(this);
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
_display = View.maybeOf(context)?.display;
|
|
unawaited(_aplicarPoliticaOrientacion(_display));
|
|
}
|
|
|
|
@override
|
|
void didChangeMetrics() {
|
|
unawaited(_aplicarPoliticaOrientacion(_display));
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => widget.child;
|
|
}
|