Skip to content

Commit

Permalink
improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
gokadzev committed Aug 21, 2022
1 parent 70c8a5b commit 5ea0b2f
Show file tree
Hide file tree
Showing 26 changed files with 394 additions and 333 deletions.
6 changes: 6 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ linter:
- non_constant_identifier_names
- noop_primitive_operations
- null_closures
- omit_local_variable_types
- overridden_fields
- package_api_docs
- package_names
Expand All @@ -64,9 +65,13 @@ linter:
- prefer_single_quotes
- prefer_typing_uninitialized_variables
- recursive_getters
- require_trailing_commas
- sized_box_for_whitespace
- slash_for_doc_comments
- sort_child_properties_last
- sort_constructors_first
- sort_pub_dependencies
- sort_unnamed_constructors_first
- test_types_in_equals
- throw_in_finally
- type_init_formals
Expand All @@ -88,5 +93,6 @@ linter:
- use_is_even_rather_than_modulo
- use_named_constants
- use_rethrow_when_possible
- use_super_parameters
- valid_regexps
- void_checks
58 changes: 33 additions & 25 deletions lib/API/musify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Future get10Music(dynamic playlistid) async {
final List playlistSongs =
await getData('cache', 'playlist10Songs$playlistid') ?? [];
if (playlistSongs.isEmpty) {
int index = 0;
var index = 0;
await for (final song in yt.playlists.getVideos(playlistid).take(10)) {
playlistSongs.add(
returnSongLayout(
Expand Down Expand Up @@ -156,8 +156,10 @@ Future<List> searchPlaylist(String query) async {
}

return playlists
.where((playlist) =>
playlist['title'].toLowerCase().contains(query.toLowerCase()))
.where(
(playlist) =>
playlist['title'].toLowerCase().contains(query.toLowerCase()),
)
.toList();
}

Expand All @@ -172,7 +174,7 @@ Future getSongsFromPlaylist(dynamic playlistid) async {
final List playlistSongs =
await getData('cache', 'playlistSongs$playlistid') ?? [];
if (playlistSongs.isEmpty) {
int index = 0;
var index = 0;
await for (final song in yt.playlists.getVideos(playlistid)) {
playlistSongs.add(
returnSongLayout(
Expand All @@ -199,7 +201,7 @@ Future<void> setActivePlaylist(List plist) async {
if (plist is List<SongModel>) {
activePlaylist = [];
id = 0;
final List<MediaItem> activeTempPlaylist = [
final activeTempPlaylist = <MediaItem>[
for (final song in plist) songModelToMediaItem(song, song.data)
];

Expand Down Expand Up @@ -258,7 +260,8 @@ Future<List<SongModel>> getLocalSongs() async {
localSongs = [
...await _audioQuery.querySongs(uriType: UriType.EXTERNAL),
...await _audioQuery.querySongs(
path: await ExtStorageProvider.getExtStorage(dirName: 'Musify'))
path: await ExtStorageProvider.getExtStorage(dirName: 'Musify'),
)
];
}

Expand All @@ -267,23 +270,25 @@ Future<List<SongModel>> getLocalSongs() async {

Future<List<Map<String, int>>> getSkipSegments(String id) async {
try {
final res = await http.get(Uri(
scheme: 'https',
host: 'sponsor.ajay.app',
path: '/api/skipSegments',
queryParameters: {
'videoID': id,
'category': [
'sponsor',
'selfpromo',
'interaction',
'intro',
'outro',
'music_offtopic'
],
'actionType': 'skip'
},
));
final res = await http.get(
Uri(
scheme: 'https',
host: 'sponsor.ajay.app',
path: '/api/skipSegments',
queryParameters: {
'videoID': id,
'category': [
'sponsor',
'selfpromo',
'interaction',
'intro',
'outro',
'music_offtopic'
],
'actionType': 'skip'
},
),
);
if (res.body != 'Not Found') {
final data = jsonDecode(res.body);
final segments = data.map((obj) {
Expand Down Expand Up @@ -341,8 +346,11 @@ Future getSongLyrics(String artist, String title) async {
final lyricsResponse = await json.decode(response.body);
if (lyricsResponse['lyrics'] != null) {
lyrics.value = lyricsResponse['lyrics'].toString();
addOrUpdateData('cache', 'lyrics-$artist-$title',
lyricsResponse['lyrics'].toString());
addOrUpdateData(
'cache',
'lyrics-$artist-$title',
lyricsResponse['lyrics'].toString(),
);
} else {
lyrics.value = 'not found';
}
Expand Down
4 changes: 2 additions & 2 deletions lib/customWidgets/custom_animated_bottom_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:musify/ui/rootPage.dart';

class CustomAnimatedBottomBar extends StatelessWidget {
CustomAnimatedBottomBar({
Key? key,
super.key,
this.showElevation = true,
this.onTap,
this.selectedItemColor,
Expand All @@ -17,7 +17,7 @@ class CustomAnimatedBottomBar extends StatelessWidget {
this.curve = Curves.easeOutQuint,
this.radius = BorderRadius.zero,
required this.items,
}) : super(key: key);
});
final Color? backgroundColor;
final bool showElevation;
final List<BottomNavBarItem> items;
Expand Down
22 changes: 11 additions & 11 deletions lib/customWidgets/delayed_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import 'dart:async';
import 'package:flutter/material.dart';

class DelayedDisplay extends StatefulWidget {
/// DelayedDisplay constructor
const DelayedDisplay({
required this.child,
this.delay = Duration.zero,
this.fadingDuration = const Duration(milliseconds: 800),
this.slidingCurve = Curves.decelerate,
this.slidingBeginOffset = const Offset(0, 0.35),
this.fadeIn = true,
});

/// Child that will be displayed with the animation and delay
final Widget child;

Expand All @@ -23,16 +33,6 @@ class DelayedDisplay extends StatefulWidget {
/// If true, make the child appear, disappear otherwise. Default to true.
final bool fadeIn;

/// DelayedDisplay constructor
const DelayedDisplay({
required this.child,
this.delay = Duration.zero,
this.fadingDuration = const Duration(milliseconds: 800),
this.slidingCurve = Curves.decelerate,
this.slidingBeginOffset = const Offset(0, 0.35),
this.fadeIn = true,
});

@override
_DelayedDisplayState createState() => _DelayedDisplayState();
}
Expand Down Expand Up @@ -74,7 +74,7 @@ class _DelayedDisplayState extends State<DelayedDisplay>
duration: opacityTransitionDuration,
);

final CurvedAnimation curvedAnimation = CurvedAnimation(
final curvedAnimation = CurvedAnimation(
curve: slidingCurve,
parent: _opacityController,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/customWidgets/setting_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'package:flutter/material.dart';
import 'package:musify/style/appColors.dart';

class SettingBar extends StatelessWidget {
SettingBar(this.tileName, this.tileIcon, this.onTap);

final Function() onTap;
final String tileName;
final IconData tileIcon;

SettingBar(this.tileName, this.tileIcon, this.onTap);

@override
Widget build(BuildContext context) {
return Padding(
Expand Down
16 changes: 9 additions & 7 deletions lib/customWidgets/song_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:musify/services/download_manager.dart';
import 'package:musify/style/appColors.dart';

class SongBar extends StatelessWidget {
SongBar(this.song, this.moveBackAfterPlay, {Key? key}) : super(key: key);
SongBar(this.song, this.moveBackAfterPlay, {super.key});

late final dynamic song;
late final bool moveBackAfterPlay;
Expand Down Expand Up @@ -66,9 +66,10 @@ class SongBar extends StatelessWidget {
.replaceAll('&quot;', '"')
.replaceAll('&amp;', '&'),
style: TextStyle(
color: accent,
fontSize: 16,
fontWeight: FontWeight.w700),
color: accent,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
),
const SizedBox(
Expand All @@ -80,9 +81,10 @@ class SongBar extends StatelessWidget {
overflow: TextOverflow.ellipsis,
song['more_info']['singers'].toString(),
style: const TextStyle(
color: Colors.white70,
fontWeight: FontWeight.w400,
fontSize: 14),
color: Colors.white70,
fontWeight: FontWeight.w400,
fontSize: 14,
),
),
),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/customWidgets/spinner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:musify/style/appColors.dart';

class Spinner extends StatelessWidget {
const Spinner({Key? key}) : super(key: key);
const Spinner({super.key});

@override
Widget build(BuildContext context) {
Expand Down
8 changes: 4 additions & 4 deletions lib/helper/material_color_creator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import 'package:flutter/material.dart';

MaterialColor createMaterialColor(Color color) {
final List strengths = <double>[.05];
final Map<int, Color> swatch = {};
final int r = color.red, g = color.green, b = color.blue;
final swatch = <int, Color>{};
final r = color.red, g = color.green, b = color.blue;

for (int i = 1; i < 10; i++) {
for (var i = 1; i < 10; i++) {
strengths.add(0.1 * i);
}
for (var strength in strengths) {
final double ds = 0.5 - strength;
final ds = 0.5 - strength;
swatch[(strength * 1000).round()] = Color.fromRGBO(
r + ((ds < 0 ? r : (255 - r)) * ds).round(),
g + ((ds < 0 ? g : (255 - g)) * ds).round(),
Expand Down
5 changes: 2 additions & 3 deletions lib/helper/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ Future<void> downloadAppUpdates() async {
} else {
dlUrl = map['url'].toString();
}
final String? dlPath =
await ExtStorageProvider.getExtStorage(dirName: 'Download');
final File file = File('${dlPath!}/Musify.apk');
final dlPath = await ExtStorageProvider.getExtStorage(dirName: 'Download');
final file = File('${dlPath!}/Musify.apk');
if (await file.exists()) {
await file.delete();
}
Expand Down
22 changes: 13 additions & 9 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ GetIt getIt = GetIt.instance;
bool _interrupted = false;

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({super.key});

static Future<void> setLocale(BuildContext context, Locale newLocale) async {
final _MyAppState state = context.findAncestorStateOfType<_MyAppState>()!;
final state = context.findAncestorStateOfType<_MyAppState>()!;
state.changeLanguage(newLocale);
}

static Future<void> setAccentColor(
BuildContext context, Color newAccentColor) async {
final _MyAppState state = context.findAncestorStateOfType<_MyAppState>()!;
BuildContext context,
Color newAccentColor,
) async {
final state = context.findAncestorStateOfType<_MyAppState>()!;
state.changeAccentColor(newAccentColor);
}

Expand All @@ -56,7 +58,7 @@ class _MyAppState extends State<MyApp> {
void initState() {
super.initState();
getLocalSongs();
final Map<String, String> codes = {
final codes = <String, String>{
'English': 'en',
'Georgian': 'ka',
'Chinese': 'zh',
Expand All @@ -70,8 +72,10 @@ class _MyAppState extends State<MyApp> {
'Turkish': 'tr',
'Ukrainian': 'uk',
};
_locale = Locale(codes[Hive.box('settings')
.get('language', defaultValue: 'English') as String]!);
_locale = Locale(
codes[Hive.box('settings').get('language', defaultValue: 'English')
as String]!,
);

FlutterDownloader.registerCallback(downloadCallback);
}
Expand Down Expand Up @@ -184,7 +188,7 @@ Future<void> initialisation() async {
_interrupted = false;
}
});
final AudioHandler audioHandler = await AudioService.init(
final audioHandler = await AudioService.init(
builder: MyAudioHandler.new,
config: const AudioServiceConfig(
androidNotificationChannelId: 'com.gokadzev.musify',
Expand All @@ -200,7 +204,7 @@ Future<void> initialisation() async {
debug: kDebugMode,
ignoreSsl: true,
);
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
final packageInfo = await PackageInfo.fromPlatform();
version = packageInfo.version;
}

Expand Down
Loading

0 comments on commit 5ea0b2f

Please sign in to comment.