Skip to content

Commit

Permalink
Migrate to sound null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
mvolpato committed Mar 13, 2021
1 parent f7746a5 commit ae460c3
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 64 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.3] - migrate to sound null safety
### Changed
- code is now sound null safe

## [0.0.2] - add playlist
### Added
- this changelog
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ the package [just_audio](https://pub.dev/packages/just_audio).
In the [second part](https://ishouldgotosleep.com/tutorials/music-app/repository-management-and-add-playlist/)
we improve the repository and we add a playlist to the app.

<img alt="The UI at the end of the first part" src="https://ishouldgotosleep.com/assets/images/blog/music-app/playlist.png" width="200" height="433">
<img alt="The UI at the end of the first part" src="https://ishouldgotosleep.com/assets/images/blog/music-app/playlist.png" width="200" height="433">

### Part 3: Migrate to Flutter 2, sound null safety, and select a license

The [third part](https://ishouldgotosleep.com/tutorials/music-app/update-flutter-2-null-safety-add-license/)
is all about upgrading Flutter and migrate to sound null safety. We also select a
license for the project.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
audio_session: 4f3e461722055d21515cf3261b64c973c062f345
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
just_audio: baa7252489dbcf47a4c7cc9ca663e9661c99aafa
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/domain/audio_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ class AudioMetadata {
/// URL to an image representing this audio source.
final String artwork;

AudioMetadata({this.title, this.artwork});
// TODO change placeholder
AudioMetadata(
{required this.title, this.artwork = 'https://via.placeholder.com/150'});
}
10 changes: 5 additions & 5 deletions lib/screens/commons/player_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:just_audio/just_audio.dart';
///
/// The order is: shuffle, previous, play/pause/restart, next, repeat.
class PlayerButtons extends StatelessWidget {
const PlayerButtons(this._audioPlayer, {Key key}) : super(key: key);
const PlayerButtons(this._audioPlayer, {Key? key}) : super(key: key);

final AudioPlayer _audioPlayer;

Expand All @@ -31,7 +31,7 @@ class PlayerButtons extends StatelessWidget {
},
),
// Previous
StreamBuilder<SequenceState>(
StreamBuilder<SequenceState?>(
stream: _audioPlayer.sequenceStateStream,
builder: (_, __) {
return _previousButton();
Expand All @@ -46,7 +46,7 @@ class PlayerButtons extends StatelessWidget {
},
),
// Next
StreamBuilder<SequenceState>(
StreamBuilder<SequenceState?>(
stream: _audioPlayer.sequenceStateStream,
builder: (_, __) {
return _nextButton();
Expand All @@ -69,7 +69,7 @@ class PlayerButtons extends StatelessWidget {
/// If the audio has finished playing, a restart button is shown.
/// If the audio is paused, or not started yet, a play button is shown.
/// If the audio is loading, a progress indicator is shown.
Widget _playPauseButton(PlayerState playerState) {
Widget _playPauseButton(PlayerState? playerState) {
final processingState = playerState?.processingState;
if (processingState == ProcessingState.loading ||
processingState == ProcessingState.buffering) {
Expand All @@ -96,7 +96,7 @@ class PlayerButtons extends StatelessWidget {
icon: Icon(Icons.replay),
iconSize: 64.0,
onPressed: () => _audioPlayer.seek(Duration.zero,
index: _audioPlayer.effectiveIndices.first),
index: _audioPlayer.effectiveIndices?.first),
);
}
}
Expand Down
7 changes: 4 additions & 3 deletions lib/screens/commons/playlist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import 'package:just_audio/just_audio.dart';
/// Audio sources are displayed with a `ListTile` with a leading image (the
/// artwork), and the title of the audio source.
class Playlist extends StatelessWidget {
const Playlist(this._audioPlayer, {Key key}) : super(key: key);
const Playlist(this._audioPlayer, {Key? key}) : super(key: key);

final AudioPlayer _audioPlayer;

Widget build(BuildContext context) {
return StreamBuilder<SequenceState>(
return StreamBuilder<SequenceState?>(
stream: _audioPlayer.sequenceStateStream,
builder: (context, snapshot) {
final state = snapshot.data;
final sequence = state?.sequence ?? [];
if (state == null) return CircularProgressIndicator();
final sequence = state.sequence;
return ListView(
children: [
for (var i = 0; i < sequence.length; i++)
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Player extends StatefulWidget {
}

class _PlayerState extends State<Player> {
AudioPlayer _audioPlayer;
late AudioPlayer _audioPlayer;

@override
void initState() {
Expand Down
Loading

0 comments on commit ae460c3

Please sign in to comment.