team-2/CHALLENGE_2/sleepysound/lib/main.dart
2025-08-02 04:48:34 +02:00

122 lines
3.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'pages/now_playing_page.dart';
import 'pages/voting_page.dart';
import 'pages/group_page.dart';
import 'services/music_queue_service.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => MusicQueueService(),
child: MaterialApp(
title: 'SleepySound',
theme: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFF6366F1),
brightness: Brightness.dark,
),
scaffoldBackgroundColor: const Color(0xFF121212),
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFF1E1E1E),
foregroundColor: Colors.white,
),
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
backgroundColor: Color(0xFF1E1E1E),
selectedItemColor: Color(0xFF6366F1),
unselectedItemColor: Colors.grey,
type: BottomNavigationBarType.fixed,
),
),
home: const MyHomePage(title: 'Now Playing'),
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
Widget _getSelectedPage() {
switch (_selectedIndex) {
case 0:
return const NowPlayingPage();
case 1:
return const VotingPage();
case 2:
return const GroupPage();
default:
return const NowPlayingPage();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(_getPageTitle()),
),
body: _getSelectedPage(),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.play_circle_filled),
label: 'Now Playing',
),
BottomNavigationBarItem(
icon: Icon(Icons.how_to_vote),
label: 'Voting',
),
BottomNavigationBarItem(
icon: Icon(Icons.group),
label: 'Group',
),
],
currentIndex: _selectedIndex,
backgroundColor: const Color(0xFF1E1E1E),
selectedItemColor: const Color(0xFF6366F1),
unselectedItemColor: Colors.grey,
type: BottomNavigationBarType.fixed,
onTap: _onItemTapped,
),
);
}
String _getPageTitle() {
switch (_selectedIndex) {
case 0:
return 'Now Playing';
case 1:
return 'Voting';
case 2:
return 'Group';
default:
return 'Now Playing';
}
}
}