Skip to content

Instantly share code, notes, and snippets.

View apptects's full-sized avatar
🤓
Learning all day...

Gero Gerber apptects

🤓
Learning all day...
View GitHub Profile
import AppKit
import RealityKit
class GameViewController: NSViewController {
@IBOutlet var arView: ARView!
override func awakeFromNib() {
// Generating the initial mesh (just so that we can extract its MeshResource.Model, which contains the actual mesh data)
@apptects
apptects / audioplayerduration.dart
Created April 8, 2019 10:58
Listening to audio player duration updates
AudioPlayerWrapper._internal() {
_audioPlayer.onAudioPositionChanged.listen(_onAudioDurationChange);
}
_onAudioDurationChange(Duration duration) {
store.dispatch(AudioDurationChangedAction(duration));
}
playTrack(String url) async {
var previewFilename = await _audioDownloader.downloadUrl(url);
await _audioPlayer.play(previewFilename, isLocal: true);
store.dispatch(PlayAudioUrlAction(url));
}
@apptects
apptects / audiodownloader.dart
Created April 8, 2019 10:50
Audio clip downloader
class AudioDownloader {
static final AudioDownloader _singleton = new AudioDownloader._internal();
factory AudioDownloader() {
return _singleton;
}
AudioDownloader._internal();
Future<String> downloadUrl(String url) async {
@apptects
apptects / navigation.dart
Created April 8, 2019 10:45
Navigate to AlbumDetail route
class _TrackButtonShowAlbumDetails extends StatelessWidget {
final TrackItem _trackItem;
_TrackButtonShowAlbumDetails(this._trackItem);
@override
Widget build(BuildContext context) {
return IconButton(
icon: Icon(Icons.dehaze),
color: Theme.of(context).buttonColor,
@apptects
apptects / rest.dart
Created April 8, 2019 10:18
Dispatch action from asynchronous function
ThunkAction<AppState> getSearchResult = (Store<AppState> store) async {
var response = await http.get(Uri.encodeFull('https://itunes.apple.com/search?term=' + store.state.searchText));
store.dispatch(UpdateTrackItemsAction(_decodeTrackItems(_decodeResultItems(response.body))));
};
@apptects
apptects / searchresultlist.dart
Created April 8, 2019 09:35
Use StoreConnector to create view-model
class _SearchResultListState extends State<SearchResultList> {
@override
Widget build(BuildContext context) {
return StoreConnector<AppState, List<TrackItem>>(
converter: (store) => store.state.trackItems,
builder: (_, trackItems) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
leading: ApptectsButton()
@apptects
apptects / reducer.dart
Created April 8, 2019 09:20
Redux Reducer
AppState reducer(AppState oldState, dynamic action) {
if(action is ChangeSearchTextAction) {
return oldState.copyWith(searchText: action.searchText);
} else if (action is UpdateTrackItemsAction) {
return oldState.copyWith(trackItems: action.trackItems);
} else if (action is PlayAudioUrlAction) {
return oldState.copyWith(activePlayingAudioUrl: action.audioUrl);
} else if (action is StopAudioAction) {
return oldState.copyWith(activePlayingAudioUrl: '');
@apptects
apptects / main.dart
Created April 8, 2019 09:14
Creating the Redux Store
Store<AppState> store;
void main() {
store = Store<AppState>(
reducer,
initialState: AppState.initial(),
middleware: [thunkMiddleware]
);
runApp(FlutteriTunesApp(store));
@apptects
apptects / pubspec.yaml
Created April 5, 2019 14:57
Adding Redux package to Flutter project
dependencies:
flutter:
sdk: flutter
flutter_redux: ^0.5.3