Select Git revision
homepage.dart
-
Erik Hinkelmanns authored
# Conflicts: # lib/moodpage.dart
Erik Hinkelmanns authored# Conflicts: # lib/moodpage.dart
homepage.dart 11.15 KiB
import 'dart:async';
import 'package:ambient/widgets/MusicPlayerState.dart';
import 'package:drop_shadow_image/drop_shadow_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:spotify_sdk/models/connection_status.dart';
import 'package:spotify_sdk/models/track.dart';
import 'package:spotify_sdk/spotify_sdk.dart';
import 'main.dart';
///After Login/Registration thr routing will bring you to this page
///This page will render the main MusicPlayer
class HomePage extends StatelessWidget {
final pageController;
const HomePage({super.key, this.pageController});
/// the root of the page will be rendered if the connection status changes or
/// a function emits in the rebuildStream
@override
Widget build(BuildContext context) {
return StreamBuilder<ConnectionStatus>(
stream: SpotifySdk.subscribeConnectionStatus(),
builder: (context, snapshot) {
var data = snapshot.data;
if (data != null) {
MusicPlayerState.of(context).connected = data.connected;
}
return StreamBuilder<void>(
stream: MusicPlayerState.of(context).rebuildStream.stream,
builder: (context, _) => player(context),
);
},
);
}
/// builds PlayerStateWidget if the app is connected to Spotify,
/// otherwise it will display a connection button, that will initiate
/// the connection to the local spotify app on click
Widget player(BuildContext context) {
return Stack(children: [
Center(
child: ListView(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
children: [
MusicPlayerState.of(context).connected
? _buildPlayerStateWidget(context)
: Center(
child: MaterialButton(
minWidth: 200,
height: 200,
color: Colors.blue,
textColor: Colors.white,
shape: const CircleBorder(),
child: const Icon(
Icons.connected_tv,
size: 50,
),
onPressed: () async {
await MusicPlayerState.of(context)
.connectToSpotifyRemote();
buildSnackbar(context);
},
),
),
IconButton(