-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
285 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import 'package:Raylex/logic/models/songInfo.dart'; | ||
import 'package:path/path.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
|
||
class LoveDb{ | ||
get tableLove => "loved"; | ||
|
||
Future<Database> db() async { | ||
return openDatabase( | ||
join(await getDatabasesPath(), 'loved_database.db'), | ||
onCreate: (db, version) { | ||
return db.execute( | ||
'CREATE TABLE IF NOT EXISTS $tableLove(id INTEGER PRIMARY KEY, artist TEXT, title TEXT, album TEXT, albumId INTERGER, duration INTEGER, uri TEXT, albumArt TEXT, trackId INTEGER)', | ||
); | ||
}, | ||
// Version provides path to perform database upgrades and downgrades. | ||
version: 1, | ||
); | ||
} | ||
|
||
|
||
Future<void> insertLove(SongInfo songInfo) async { | ||
// Get a reference to the database. | ||
final Database database = await db(); | ||
|
||
// Insert the Product into the correct table. | ||
// Specify `conflictAlgorithm`. | ||
// In this case, if the same product is inserted | ||
// multiple times, it replaces the previous data. | ||
await database.insert( | ||
tableLove, | ||
songInfo.toMap(), | ||
conflictAlgorithm: ConflictAlgorithm.replace, | ||
); | ||
} | ||
|
||
Future<void> deleteLove(int id) async { | ||
// Get a reference to the database. | ||
final database = await db(); | ||
|
||
// Remove the Product from the database. | ||
await database.delete( | ||
tableLove, | ||
// Use a `where` clause to delete a specific product. | ||
where: "id = ?", | ||
// Pass the Products's id as a whereArg to prevent SQL injection. | ||
whereArgs: [id], | ||
); | ||
} | ||
|
||
Future<List<SongInfo>> allLove() async { | ||
// Get a reference to the database. | ||
final Database database = await db(); | ||
|
||
// Query the table for all The Products. | ||
final List<Map<String, dynamic>> maps = await database.query(tableLove); | ||
|
||
// Convert the List<Map<String, dynamic> into a List<Product>. | ||
return List.generate( | ||
maps.length, | ||
(i) { | ||
return SongInfo( | ||
maps[i]['id'], | ||
maps[i]['artist'], | ||
maps[i]['title'], | ||
maps[i]['album'], | ||
maps[i]['albumId'], | ||
maps[i]['duration'], | ||
maps[i]['uri'], | ||
maps[i]['albumArt'], | ||
maps[i]['trackId'] | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:Raylex/logic/loveDb.dart'; | ||
import 'package:Raylex/logic/models/playerStateNotify.dart'; | ||
import 'package:Raylex/logic/models/songInfo.dart'; | ||
import 'package:Raylex/ux/components/lists/songList.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class FutureLoveSongList extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
var appstate = Provider.of<PlayerStateNotify>(context, listen: false); | ||
return FutureBuilder( | ||
future: LoveDb().allLove(), | ||
builder: (context, snap){ | ||
if(snap.data!=null){ | ||
List<SongInfo> songinfos = snap.data; | ||
if(songinfos.isNotEmpty) | ||
return SongList(songinfos,isInLovePlaylist: true,); | ||
else | ||
return Center(child: Text("Mark heart to have song here"),); | ||
}else{ | ||
return Center( | ||
child: CupertinoActivityIndicator(), | ||
); | ||
} | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.