Skip to content

Commit

Permalink
Made the app go beep 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
amalthomas-exe committed Mar 8, 2022
1 parent 6df1f95 commit cbb715a
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 5 deletions.
30 changes: 27 additions & 3 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:torch_light/torch_light.dart';
import '../utils/converter.dart';
import 'package:audioplayers/audioplayers.dart';

class FlashHome extends StatefulWidget {
const FlashHome({Key? key}) : super(key: key);
Expand All @@ -15,13 +16,18 @@ class FlashHomeState extends State<FlashHome> {
final TextEditingController _input = TextEditingController();
final TextEditingController _output = TextEditingController();
final FocusNode _inputFocus = FocusNode();

static AudioCache player = AudioCache(prefix: 'sounds/');
bool _alreadyFlashing = false;
bool _alreadyBeeping = false;

void _setFlashing(bool already) async {
_alreadyFlashing = already;
}

void _setBeeping(bool already) async{
_alreadyBeeping = already;
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -154,7 +160,9 @@ class FlashHomeState extends State<FlashHome> {
),
],
),
floatingActionButton: FloatingActionButton.extended(
floatingActionButton: Column(
mainAxisAlignment:MainAxisAlignment.end,
children:[FloatingActionButton.extended(
onPressed: () async {
if (_output.text.trim().isEmpty) {
showMsg("Type something to flash! 👀");
Expand All @@ -174,7 +182,23 @@ class FlashHomeState extends State<FlashHome> {
_setFlashing(false);
},
label: const Text("Flash 🔦"),
),
),
const SizedBox(height: 20),
FloatingActionButton.extended(onPressed: () async{
if(_output.text.trim().isEmpty){
showMsg("Type something to beep 👀");
_inputFocus.requestFocus();
return;
}
if(_alreadyBeeping){
return showMsg("Already beeping! 🤔");
}
_setBeeping(true);
await XooniMorse.beepIt(_output.text.trim());
_setBeeping(false);
},
label: const Text("Beep 🔊"))],
)
);
}
}
18 changes: 17 additions & 1 deletion lib/utils/converter.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:torch_light/torch_light.dart';
import 'package:audioplayers/audioplayers.dart';

class XooniMorse {
static const morseCode = {
Expand Down Expand Up @@ -60,7 +61,7 @@ class XooniMorse {
" ": "\t",
"\n": "\n",
};

static AudioCache player = AudioCache(prefix: 'sounds/');
static String convert(String phrase) {
String result = "";
phrase.toUpperCase().split(" ").forEach((word) {
Expand Down Expand Up @@ -97,4 +98,19 @@ class XooniMorse {
}
}
}

static Future<void> beepIt(String morse) async{
const duration = Duration(milliseconds: 500);
for (int i=0; i < morse.length ;i++){
if(morse[i]=="-"){
await player.play('beepLong.wav');
await Future.delayed(duration);
}else if(morse[i]=="."){
await player.play('beepShort.wav');
await Future.delayed(duration);
}else{
await Future.delayed(duration);
}
}
}
}
135 changes: 134 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
audioplayers:
dependency: "direct main"
description:
name: audioplayers
url: "https://pub.dartlang.org"
source: hosted
version: "0.20.1"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -50,6 +57,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -64,6 +78,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -93,6 +121,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "8.0.9"
http:
dependency: transitive
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.4"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
js:
dependency: transitive
description:
Expand Down Expand Up @@ -142,6 +184,76 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
path_provider:
dependency: transitive
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.9"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.12"
path_provider_ios:
dependency: transitive
description:
name: path_provider_ios
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.4"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -203,13 +315,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
uuid:
dependency: transitive
description:
name: uuid
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.6"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0+1"
sdks:
dart: ">=2.16.1 <3.0.0"
flutter: ">=1.20.0"
flutter: ">=2.8.0"
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
torch_light: ^0.4.0
fluttertoast: ^8.0.9
animated_splash_screen: ^1.2.0
audioplayers: ^0.20.1

dev_dependencies:
flutter_test:
Expand All @@ -24,3 +25,4 @@ flutter:
uses-material-design: true
assets:
- images/
- sounds/
Binary file added sounds/beepLong.wav
Binary file not shown.
Binary file added sounds/beepShort.wav
Binary file not shown.

0 comments on commit cbb715a

Please sign in to comment.