Files
kryz-go-flutter/lib/main.dart
T
2026-04-29 03:20:20 +00:00

119 lines
2.9 KiB
Dart

import 'package:flutter/material.dart';
import 'streaming_audio_business_object.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Split Screen Player',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueGrey),
),
home: const MainPage(),
debugShowCheckedModeBanner: false,
);
}
}
class MainPage extends StatefulWidget {
const MainPage({super.key});
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
final StreamingAudioBusinessObject _audio = StreamingAudioBusinessObject();
@override
void initState() {
super.initState();
_audio.addListener(_handleAudioStateChanged);
}
void _handleAudioStateChanged() {
if (!mounted) {
return;
}
setState(() {
// Rebuild when playback state changes from the player.
});
}
Future<void> _play() async {
await _audio.play();
}
Future<void> _stop() async {
await _audio.pause();
}
@override
void dispose() {
_audio.removeListener(_handleAudioStateChanged);
_audio.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
Expanded(
flex: 9,
child: Padding(
padding: const EdgeInsets.all(12),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
border: Border.all(color: Colors.black26, width: 2),
borderRadius: BorderRadius.circular(8),
color: Colors.white,
),
),
),
),
Expanded(
flex: 1,
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 16),
color: Colors.black87,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _audio.isPlaying ? null : _play,
child: const Text('Play'),
),
const SizedBox(width: 12),
ElevatedButton(
onPressed: _audio.isPlaying ? _stop : null,
child: const Text('Stop'),
),
const SizedBox(width: 16),
Text(
_audio.isPlaying ? 'Playing' : 'Stopped',
style: const TextStyle(color: Colors.white),
),
],
),
),
),
],
),
),
);
}
}