team-2/CHALLENGE_2/sleepysound/lib/main.dart

123 lines
3.2 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2025-08-02 04:48:34 +02:00
import 'package:provider/provider.dart';
2025-08-02 03:04:20 +02:00
import 'pages/now_playing_page.dart';
2025-08-02 03:42:56 +02:00
import 'pages/voting_page.dart';
import 'pages/group_page.dart';
2025-08-02 04:48:34 +02:00
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) {
2025-08-02 04:48:34 +02:00
return ChangeNotifierProvider(
create: (context) => MusicQueueService(),
child: MaterialApp(
title: 'SleepySound',
theme: ThemeData(
useMaterial3: true,
2025-08-02 03:42:56 +02:00
brightness: Brightness.dark,
2025-08-02 04:48:34 +02:00
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,
),
2025-08-02 03:42:56 +02:00
),
2025-08-02 04:48:34 +02:00
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> {
2025-08-02 03:04:20 +02:00
int _selectedIndex = 0;
2025-08-02 03:04:20 +02:00
void _onItemTapped(int index) {
setState(() {
2025-08-02 03:04:20 +02:00
_selectedIndex = index;
});
}
2025-08-02 03:04:20 +02:00
Widget _getSelectedPage() {
switch (_selectedIndex) {
case 0:
return const NowPlayingPage();
case 1:
2025-08-02 03:42:56 +02:00
return const VotingPage();
2025-08-02 03:04:20 +02:00
case 2:
2025-08-02 03:42:56 +02:00
return const GroupPage();
2025-08-02 03:04:20 +02:00
default:
return const NowPlayingPage();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
2025-08-02 03:04:20 +02:00
title: Text(_getPageTitle()),
),
2025-08-02 03:04:20 +02:00
body: _getSelectedPage(),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.play_circle_filled),
label: 'Now Playing',
),
BottomNavigationBarItem(
2025-08-02 03:42:56 +02:00
icon: Icon(Icons.how_to_vote),
2025-08-02 03:10:13 +02:00
label: 'Voting',
2025-08-02 03:04:20 +02:00
),
BottomNavigationBarItem(
2025-08-02 03:10:13 +02:00
icon: Icon(Icons.group),
label: 'Group',
2025-08-02 03:04:20 +02:00
),
],
currentIndex: _selectedIndex,
2025-08-02 03:42:56 +02:00
backgroundColor: const Color(0xFF1E1E1E),
selectedItemColor: const Color(0xFF6366F1),
unselectedItemColor: Colors.grey,
type: BottomNavigationBarType.fixed,
2025-08-02 03:04:20 +02:00
onTap: _onItemTapped,
),
);
}
2025-08-02 03:04:20 +02:00
String _getPageTitle() {
switch (_selectedIndex) {
case 0:
return 'Now Playing';
case 1:
2025-08-02 03:10:13 +02:00
return 'Voting';
2025-08-02 03:04:20 +02:00
case 2:
2025-08-02 03:10:13 +02:00
return 'Group';
2025-08-02 03:04:20 +02:00
default:
return 'Now Playing';
}
}
}