-
Notifications
You must be signed in to change notification settings - Fork 2
Lab 4 #6
base: main
Are you sure you want to change the base?
Lab 4 #6
Changes from all commits
fe76363
69e5915
8016df4
b47cb2b
8853342
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # hw_3 | ||
| # hw_4 | ||
|
|
||
| A new Flutter project. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import 'package:flutter/cupertino.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'themes.dart'; | ||
|
|
||
| class ThemeManagement with ChangeNotifier { | ||
| ThemeData _currentTheme = mainTheme; | ||
|
|
||
| ThemeData get currentTheme => _currentTheme; | ||
|
|
||
| void toggleTheme() { | ||
| _currentTheme = _currentTheme == mainTheme ? secondTheme : mainTheme; | ||
| notifyListeners(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| ThemeData mainTheme = ThemeData( | ||
| brightness: Brightness.dark, | ||
| bottomNavigationBarTheme: | ||
| const BottomNavigationBarThemeData(selectedItemColor: Colors.white), | ||
| ); | ||
|
|
||
| ThemeData secondTheme = ThemeData( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better to use |
||
|
|
||
| brightness: Brightness.light, | ||
| bottomNavigationBarTheme: | ||
| const BottomNavigationBarThemeData(selectedItemColor: Colors.black), | ||
|
|
||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import 'dart:math'; | ||
|
|
||
| import 'package:flutter/cupertino.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:hw_3/data/data.dart'; | ||
|
|
||
| class ImageManagement with ChangeNotifier { | ||
| String _randomImage = currentUser.imageUrl; | ||
| String get randomImage => _randomImage; | ||
|
|
||
| void generateRandomImage() { | ||
| var random = new Random(); | ||
| int min = 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. too many variables, just use |
||
| int max = 63707307; | ||
| int result = min + random.nextInt(max - min); | ||
| _randomImage = 'https://avatars.githubusercontent.com/u/$result'; | ||
| notifyListeners(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,30 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter/services.dart'; | ||
| import 'package:hw_3/globalStateManagement/themeManagement.dart'; | ||
|
|
||
| import 'package:hw_3/screens/nav_screen.dart'; | ||
| import 'package:provider/provider.dart'; | ||
|
|
||
| import 'globalStateManagement/userImageManagement.dart'; | ||
|
|
||
| void main() { | ||
| runApp(MyApp()); | ||
| runApp(MultiProvider(providers: [ | ||
| ChangeNotifierProvider(create: (_) => ImageManagement()), | ||
| ChangeNotifierProvider(create: (_) => ThemeManagement()), | ||
| ], child: MyApp())); | ||
| } | ||
|
|
||
| class MyApp extends StatelessWidget { | ||
| const MyApp({Key? key}) : super(key: key); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| // var incrementValue = context.watch<Increment>().count; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont leave commented blocks of code |
||
|
|
||
| return MaterialApp( | ||
| title: 'Flutter YouTube UI', | ||
| debugShowCheckedModeBanner: false, | ||
| theme: ThemeData( | ||
| brightness: Brightness.dark, | ||
| bottomNavigationBarTheme: | ||
| const BottomNavigationBarThemeData(selectedItemColor: Colors.white), | ||
| ), | ||
| home: NavScreen(), | ||
| ); | ||
| title: 'Flutter YouTube UI', | ||
| debugShowCheckedModeBanner: false, | ||
| theme: context.watch<ThemeManagement>().currentTheme, | ||
| home: NavScreen()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,28 @@ import 'package:hw_3/data/colors.dart'; | |
|
|
||
| import 'package:hw_3/widgets/app_bar.dart'; | ||
|
|
||
| class LibraryTab extends StatelessWidget { | ||
| class LibraryTab extends StatefulWidget { | ||
| LibraryState createState() => LibraryState(); | ||
| } | ||
|
|
||
| class LibraryState extends State<LibraryTab> { | ||
| late String temp; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just use |
||
| List playList = []; | ||
| int likeCounter = 0; | ||
|
|
||
| @override | ||
| void initState() { | ||
| super.initState(); | ||
|
|
||
| playList.addAll(['maks_playlist', 'vika_playlist', 'mykhailo_playlist']); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just use when declaring the field |
||
| } | ||
|
|
||
| void _incrementCounter() { | ||
| setState(() { | ||
| likeCounter++; | ||
| }); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
|
|
@@ -19,61 +40,124 @@ class LibraryTab extends StatelessWidget { | |
| leading: Icon(Icons.history, color: suvaGrey), | ||
| title: Text( | ||
| 'History', | ||
| style: TextStyle(color: Colors.white), | ||
| ), | ||
| ), | ||
| ListTile( | ||
| leading: Icon(Icons.file_download, color: suvaGrey), | ||
| title: Text('Downloads', style: TextStyle(color: Colors.white)), | ||
| title: Text( | ||
| 'Downloads', | ||
| ), | ||
| subtitle: Text('2 recommendations', | ||
| style: TextStyle(color: suvaGrey, fontSize: 12.0)), | ||
| ), | ||
| ListTile( | ||
| leading: Icon(Icons.video_library, color: suvaGrey), | ||
| title: | ||
| Text('Your videos', style: TextStyle(color: Colors.white)), | ||
| title: Text( | ||
| 'Your videos', | ||
| ), | ||
| ), | ||
| ListTile( | ||
| leading: Icon(Icons.attach_money, color: suvaGrey), | ||
| title: Text('Purchases', style: TextStyle(color: Colors.white)), | ||
| title: Text('Purchases'), | ||
| ), | ||
| ListTile( | ||
| leading: Icon(Icons.watch_later, color: suvaGrey), | ||
| title: | ||
| Text('Watch later', style: TextStyle(color: Colors.white)), | ||
| title: Text( | ||
| 'Watch later', | ||
| ), | ||
| subtitle: Text('Videos you save for later', | ||
| style: TextStyle(color: suvaGrey, fontSize: 12.0)), | ||
| ), | ||
| Divider(color: Colors.white), | ||
| Divider(color: suvaGrey), | ||
| Padding( | ||
| padding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0), | ||
| padding: | ||
| EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0), | ||
| child: Row( | ||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
| children: <Widget>[ | ||
| Text('Playlists', | ||
| style: TextStyle(color: Colors.white, fontSize: 16.0)), | ||
| Text('Playlists', style: TextStyle(fontSize: 16.0)), | ||
| Row( | ||
| children: <Widget>[ | ||
| Text('Recently added', | ||
| style: | ||
| TextStyle(color: Colors.white, fontSize: 16.0)), | ||
| Icon(Icons.arrow_drop_down, color: Colors.white) | ||
| style: TextStyle(fontSize: 16.0)), | ||
| Icon(Icons.arrow_drop_down, color: suvaGrey) | ||
| ], | ||
| ) | ||
| ], | ||
| ), | ||
| ), | ||
| ListTile( | ||
| onTap: () { | ||
| showDialog( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return AlertDialog( | ||
| title: Text('Add playlist'), | ||
| content: TextField( | ||
| onChanged: (String value) { | ||
| temp = value; | ||
| }, | ||
| ), | ||
| actions: [ | ||
| ElevatedButton( | ||
| onPressed: () { | ||
| setState(() { | ||
| playList.add(temp); | ||
| }); | ||
| Navigator.of(context).pop(); | ||
| }, | ||
| child: Text('Add')) | ||
| ], | ||
| ); | ||
| }); | ||
| }, | ||
| leading: Icon(Icons.add, color: linkBlue), | ||
| title: Text('New Playlist', style: TextStyle(color: linkBlue)), | ||
| title: | ||
| Text('New Playlist', style: TextStyle(color: linkBlue)), | ||
| ), | ||
| ListTile( | ||
| onTap: _incrementCounter, | ||
| leading: Icon(Icons.thumb_up, color: suvaGrey), | ||
| title: | ||
| Text('Liked videos', style: TextStyle(color: Colors.white)), | ||
| subtitle: Text('4 Videos', | ||
| title: Text( | ||
| 'Liked videos', | ||
| ), | ||
| subtitle: Text('$likeCounter Videos', | ||
| style: TextStyle(color: suvaGrey, fontSize: 12.0)), | ||
| ), | ||
| ListView.builder( | ||
| shrinkWrap: true, | ||
| itemCount: playList.length, | ||
| itemBuilder: (BuildContext context, int index) { | ||
| return Dismissible( | ||
| key: Key(playList[index]), | ||
| child: Card( | ||
| child: ListTile( | ||
| subtitle: Text('$likeCounter Videos', | ||
| style: | ||
| TextStyle(color: suvaGrey, fontSize: 12.0)), | ||
| leading: | ||
| Icon(Icons.featured_play_list, color: suvaGrey), | ||
| title: Text(playList[index]), | ||
| trailing: IconButton( | ||
| icon: Icon( | ||
| Icons.delete_sweep, | ||
| color: Colors.red, | ||
| ), | ||
| onPressed: () { | ||
| setState(() { | ||
| playList.removeAt(index); | ||
| }); | ||
| }, | ||
| ), | ||
| ), | ||
| ), | ||
| onDismissed: (direction) { | ||
| setState(() { | ||
| playList.removeAt(index); | ||
| }); | ||
| }, | ||
| ); | ||
| }), | ||
| ], | ||
| ), | ||
| ), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use something like this instead:
this will allow you to cycle through themes, and adding new themes to
themesarray without changing a code inside yourtoggle