Skip to content
Snippets Groups Projects
Select Git revision
  • d0179563c8658aa13c063e0e162a46423ede5ba7
  • main default protected
  • idacs_experiments
  • postgres_idacs
  • memgraph_fabian
  • postgres_julian
  • dev_ma
  • test_results
  • FZ_changed_code
  • FZ_Memgraph
10 results

queries.txt

Blame
  • main.dart 5.35 KiB
    import 'package:ambient/Classification/classification.dart';
    import 'package:ambient/LoginRegister/registration.dart';
    import 'package:firebase_auth/firebase_auth.dart';
    import 'package:ambient/emptyMoodpage.dart';
    import 'package:ambient/searchpage.dart';
    import 'package:ambient/widgets/MusicPlayerState.dart';
    import 'package:ambient/widgets/navbars.dart';
    import 'package:firebase_core/firebase_core.dart';
    import 'package:flutter/material.dart';
    import 'package:flutter_dotenv/flutter_dotenv.dart';
    import 'package:spotify_sdk/models/player_state.dart';
    import 'package:spotify_sdk/spotify_sdk.dart';
    
    import 'homepage.dart';
    import 'LoginRegister/login.dart';
    
    Future<void> main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp;
      await dotenv.load(fileName: '.env');
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          home: MusicPlayerState(
            child: const HUD(),
          ),
        );
      }
    }
    
    const Color primaryColor = Color(0xFFFFa74a);
    const Color onPrimary = Color(0xFFFFFFFF);
    const Color primaryContainer = Color(0xFFFFDFBD);
    const Color onPrimaryContainer = Color(0xFF312B25);
    
    class HUD extends StatefulWidget {
      const HUD({super.key});
    
      @override
      State<StatefulWidget> createState() => _HUDState();
    }
    
    class _HUDState extends State<HUD> {
      int _currentIndex = 0;
      final List<String> _titleList = ["Player", "Mood", "Search"];
      String _title = "";
      PageController _pageController = PageController(initialPage: 0);
    
      @override
      void initState() {
        _title = _titleList[0];
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            appBar: Topbar(title: Text(_title)),
            endDrawer: SettingsDrawer(),
            body: PageView(
              controller: _pageController,
              onPageChanged: (newIndex) {
                setState(() {
                  _currentIndex = newIndex;
                  _title = _titleList[newIndex];
                });
              },
              children: const [
                HomePage(),
                StateMoodPage(),
                StateSearcgPage(),
              ],
            ),
            bottomNavigationBar: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
              StreamBuilder<void>(
                stream: MusicPlayerState.of(context).rebuildStream.stream,
                builder: (context, _) {
                  if(_currentIndex != 0){
                    return MusicBar();
                  } else{
                    return const Center(child: Text('Moin'));
                  }
                }),
                BottomNavigationBar(
                  currentIndex: _currentIndex,
                  backgroundColor: ligten(primaryContainer),
                  selectedItemColor: primaryColor,
                  unselectedItemColor: Colors.black,
                  items: const [
                    BottomNavigationBarItem(
                      icon: Icon(Icons.play_arrow_rounded),
                      label: "Play",
                    ),
                    BottomNavigationBarItem(icon: Icon(Icons.mood), label: "Moods"),
                    BottomNavigationBarItem(
                        icon: Icon(Icons.search), label: "Suchen"),
                  ],
                  onTap: (newIndex) {
                    _pageController.animateToPage(newIndex,
                        duration: const Duration(milliseconds: 500),
                        curve: Curves.ease);
                    _title = _titleList[newIndex];
                  },
                ),
              ],
            ));
      }
    }
    
    class MusicBar extends StatelessWidget {
      MusicBar({
        Key? key,
      }) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        if (MusicPlayerState.of(context).connected){
          return StreamBuilder<PlayerState>(
              stream: SpotifySdk.subscribePlayerState(),
              builder: (BuildContext context, AsyncSnapshot<PlayerState> snapshot) {
                var track = snapshot.data?.track;
                MusicPlayerState.of(context).currentTrackImageUri = track?.imageUri;
                var playerState = snapshot.data;
                if (playerState == null || track == null) {
                  return const Center(
                    child: Text('PlayState or track is null'),
                  );
                }
                return Container(
                  height: 80,
                  color: Colors.grey,
                  child: Row(
                    children: [
                      MusicPlayerState.of(context).albumImage,
                      playerState.isPaused
                          ? IconButton(
                        icon: Icon(Icons.play_arrow_outlined),
                        iconSize: 50,
                        onPressed: (){
                          var state = MusicPlayerState.of(context);
                          SpotifySdk.resume().then((value) => state.rebuildStream.sink.add(Null));
                        }
                        )
                          : IconButton(
                        icon: Icon(Icons.pause_outlined),
                        iconSize: 50,
                        color: primaryColor,
                        onPressed:() {
                          var state = MusicPlayerState.of(context);
                          SpotifySdk.pause().then((value) => state.rebuildStream.sink.add(Null));
                        },
    
                      ),
                    ],
                  ),
                );
              });
        } else {
          return Text("not Connected");
        }
      }
    }