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

114 lines
3.1 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2025-08-02 03:04:20 +02:00
import 'pages/now_playing_page.dart';
import 'pages/library_page.dart';
import 'pages/settings_page.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 MaterialApp(
2025-08-02 00:05:57 +02:00
title: 'SleepySound',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
2025-08-02 00:45:58 +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:
return const LibraryPage();
case 2:
return const SettingsPage();
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(
icon: Icon(Icons.library_music),
label: 'Library',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.deepPurple,
onTap: _onItemTapped,
),
);
}
2025-08-02 03:04:20 +02:00
String _getPageTitle() {
switch (_selectedIndex) {
case 0:
return 'Now Playing';
case 1:
return 'Library';
case 2:
return 'Settings';
default:
return 'Now Playing';
}
}
}