Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
feat(soundspage): dynamically display list of sounds with ability to …
Browse files Browse the repository at this point in the history
…update current alarm, also disp

re #46
  • Loading branch information
Scott Clampet authored and Scott Clampet committed Jan 7, 2019
1 parent 7d3f040 commit 8b992a1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 34 deletions.
14 changes: 14 additions & 0 deletions lib/helpers/sounds.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:snuze/models/sound.dart';

List<Sound> sounds = [
Sound(displayName: "bounce", fileName: "bounce.mp4"),
Sound(displayName: "jiggle", fileName: "jiggle.mp4"),
Sound(displayName: "bump", fileName: "bump.mp4"),
Sound(displayName: "boing", fileName: "boing.mp4"),
Sound(displayName: "sproing", fileName: "sproing.mp4"),
Sound(displayName: "buggle", fileName: "buggle.mp4"),
Sound(displayName: "joggle", fileName: "joggle.mp4"),
Sound(displayName: "jimbo", fileName: "jimbo.mp4"),
Sound(displayName: "flimbo", fileName: "flimbo.mp4"),
Sound(displayName: "bimbo", fileName: "bimbo.mp4"),
];
2 changes: 1 addition & 1 deletion lib/models/alarm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Alarm {
String sound;


Alarm({this.hour = 6, this.minute = 6, this.meridiem = 0, this.snuzeAmount = 0.25, this.isActive = false, this.sound = "ring"});
Alarm({this.hour = 6, this.minute = 6, this.meridiem = 0, this.snuzeAmount = 0.25, this.isActive = false, this.sound = "bounce.mp4"});

factory Alarm.fromJson(Map<String, dynamic> json) => _$AlarmFromJson(json);

Expand Down
2 changes: 2 additions & 0 deletions lib/models/sound.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:json_annotation/json_annotation.dart';

part 'sound.g.dart';

@JsonSerializable()
class Sound {
String displayName;
Expand Down
35 changes: 26 additions & 9 deletions lib/pages/sounds/sound_list_item.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';

import 'package:snuze/scoped-models/main.dart';
import 'package:snuze/models/sound.dart';

class SoundListItem extends StatelessWidget {
final String sound;
final Sound sound;

SoundListItem({this.sound});

_selectSound(sound, Function updateAlarm) {
print("selecting sound and upating alarm");
updateAlarm(<String, String>{"sound": sound});
}

@override
Widget build(BuildContext context) {
print("sound:" + sound);
return ListTile(
title: Text(sound),
// trailing: Icon(Icons.check, color: Colors.red,),
onTap: () {
print("$sound tapped");
},
);
return ScopedModelDescendant<MainModel>(
builder: (BuildContext context, Widget child, MainModel model) {
return ListTile(
title: Text(sound.displayName),
trailing: model.alarm.sound == sound.fileName
? Icon(
Icons.check,
color: Colors.red,
)
: Text(''),
onTap: () {
print("$sound tapped");
_selectSound(sound.fileName, model.updateAlarm);
});
});
}
}
13 changes: 2 additions & 11 deletions lib/pages/sounds/sounds.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';

import 'package:snuze/scoped-models/main.dart';
import 'package:snuze/pages/sounds/sounds_list.dart';

class SoundsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<String> sounds = [
'ring',
'beep',
'buzz'
];
return ScopedModelDescendant<MainModel>(
builder: (BuildContext context, Widget child, MainModel model) {

return Scaffold(
appBar: AppBar(
title: Text(
Expand All @@ -22,8 +14,7 @@ class SoundsPage extends StatelessWidget {
TextStyle(fontSize: 23, color: Theme.of(context).dividerColor),
),
),
body: SoundsList(sounds: sounds),
body: SoundsList(),
);
});
}
}
25 changes: 12 additions & 13 deletions lib/pages/sounds/sounds_list.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import 'package:flutter/material.dart';

import 'package:snuze/pages/sounds/sound_list_item.dart';
import 'package:snuze/helpers/sounds.dart';

class SoundsList extends StatelessWidget {
final List<String> sounds;

SoundsList({this.sounds});

@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: sounds.length,
itemBuilder: (context, index) {
return Column(
children: <Widget>[
SoundListItem(sound: sounds[index]),
Divider(),
],
);
});

return ListView.builder(
itemCount: sounds.length,
itemBuilder: (context, index) {
return Column(
children: <Widget>[
SoundListItem(sound: sounds[index]),
Divider(),
],
);
});
}
}

0 comments on commit 8b992a1

Please sign in to comment.