Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
D
dispatcher_test
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gavin An
dispatcher_test
Commits
7421b5a0
Commit
7421b5a0
authored
Aug 16, 2024
by
Gavin An
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fcm 동작 이해
parent
5bbe2a21
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
58 deletions
+129
-58
android/gradle/wrapper/gradle-wrapper.properties
android/gradle/wrapper/gradle-wrapper.properties
+1
-1
android/settings.gradle
android/settings.gradle
+1
-1
lib/main.dart
lib/main.dart
+76
-38
lib/text_to_speech_page.dart
lib/text_to_speech_page.dart
+40
-18
lib/text_to_speech_util.dart
lib/text_to_speech_util.dart
+11
-0
No files found.
android/gradle/wrapper/gradle-wrapper.properties
View file @
7421b5a0
...
...
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
7.6.3-all
.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
8.2-bin
.zip
android/settings.gradle
View file @
7421b5a0
...
...
@@ -20,7 +20,7 @@ plugins {
id
"dev.flutter.flutter-plugin-loader"
version
"1.0.0"
id
"com.android.application"
version
"8.2.2"
apply
false
id
"org.jetbrains.kotlin.android"
version
"1.9.10"
apply
false
id
"com.google.gms.google-services"
version
"4.
3.15
"
apply
false
id
"com.google.gms.google-services"
version
"4.
4.1
"
apply
false
}
include
":app"
lib/main.dart
View file @
7421b5a0
...
...
@@ -5,11 +5,13 @@ import 'package:dispatcher_test/firebase_options.dart';
import
'package:dispatcher_test/notification_page.dart'
;
import
'package:dispatcher_test/speech_to_text_page.dart'
;
import
'package:dispatcher_test/text_to_speech_page.dart'
;
import
'package:dispatcher_test/text_to_speech_util.dart'
;
import
'package:firebase_core/firebase_core.dart'
;
import
'package:firebase_messaging/firebase_messaging.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_local_notifications/flutter_local_notifications.dart'
;
import
'package:permission_handler/permission_handler.dart'
;
import
'package:speech_to_text/speech_to_text.dart'
;
const
List
<
String
>
sample
=
[
'배고프다'
,
...
...
@@ -26,10 +28,76 @@ const List<String> sample = [
Future
<
void
>
_firebaseMessagingBackgroundHandler
(
RemoteMessage
message
)
async
{
await
Firebase
.
initializeApp
(
options:
DefaultFirebaseOptions
.
currentPlatform
);
await
setupFlutterNotifications
();
showFlutterNotification
(
message
);
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
print
(
'Handling a background message
${message.messageId}
'
);
// RemoteMessage? msg = await FirebaseMessaging.instance.getInitialMessage();
// showFlutterNotification(msg);
RemoteNotification
?
notification
=
message
.
notification
;
if
(
notification
!=
null
)
{
TextToSpeechUtil
.
speakTo
(
notification
.
body
??
''
);
}
}
void
showFlutterNotification
(
RemoteMessage
?
message
)
{
if
(
message
==
null
)
return
;
RemoteNotification
?
notification
=
message
.
notification
;
AndroidNotification
?
android
=
message
.
notification
?.
android
;
if
(
notification
!=
null
&&
android
!=
null
&&
!
kIsWeb
)
{
flutterLocalNotificationsPlugin
.
show
(
notification
.
hashCode
,
'타이틀:
${notification.title}
'
,
'바디:
${notification.body}
'
,
NotificationDetails
(
android:
AndroidNotificationDetails
(
channel
.
id
,
channel
.
name
,
channelDescription:
channel
.
description
,
icon:
'launch_background'
,
),
),
);
}
}
/// Create a [AndroidNotificationChannel] for heads up notifications
late
AndroidNotificationChannel
channel
;
bool
isFlutterLocalNotificationsInitialized
=
false
;
/// Initialize the [FlutterLocalNotificationsPlugin] package.
late
FlutterLocalNotificationsPlugin
flutterLocalNotificationsPlugin
;
Future
<
void
>
setupFlutterNotifications
()
async
{
if
(
isFlutterLocalNotificationsInitialized
)
{
return
;
}
channel
=
const
AndroidNotificationChannel
(
'high_importance_channel'
,
// id
'High Importance Notifications'
,
// title
description:
'This channel is used for important notifications.'
,
// description
importance:
Importance
.
high
,
);
flutterLocalNotificationsPlugin
=
FlutterLocalNotificationsPlugin
();
/// Create an Android Notification Channel.
///
/// We use this channel in the `AndroidManifest.xml` file to override the
/// default FCM channel to enable heads up notifications.
await
flutterLocalNotificationsPlugin
.
resolvePlatformSpecificImplementation
<
AndroidFlutterLocalNotificationsPlugin
>()?.
createNotificationChannel
(
channel
);
/// Update the iOS foreground notification presentation options to allow
/// heads up notifications.
await
FirebaseMessaging
.
instance
.
setForegroundNotificationPresentationOptions
(
alert:
true
,
badge:
true
,
sound:
true
,
);
isFlutterLocalNotificationsInitialized
=
true
;
}
...
...
@@ -37,9 +105,15 @@ void main() async {
WidgetsFlutterBinding
.
ensureInitialized
();
await
Firebase
.
initializeApp
(
options:
DefaultFirebaseOptions
.
currentPlatform
);
FirebaseMessaging
.
onBackgroundMessage
(
_firebaseMessagingBackgroundHandler
);
// FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseFirestore
.
instance
.
settings
=
const
Settings
(
persistenceEnabled:
true
,
);
// final fcmToken = await FirebaseMessaging.instance.getToken();
// print('fcmToken: $fcmToken');
if
(!
kIsWeb
)
{
await
setupFlutterNotifications
();
}
runApp
(
const
MyApp
());
}
...
...
@@ -52,21 +126,6 @@ class MyApp extends StatelessWidget {
return
MaterialApp
(
title:
'Dispatcher TEST'
,
theme:
ThemeData
(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme:
ColorScheme
.
fromSeed
(
seedColor:
Colors
.
deepPurple
),
useMaterial3:
true
,
),
...
...
@@ -77,16 +136,6 @@ class MyApp extends StatelessWidget {
class
MyHomePage
extends
StatefulWidget
{
const
MyHomePage
({
super
.
key
,
required
this
.
title
});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final
String
title
;
@override
...
...
@@ -112,20 +161,9 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget
build
(
BuildContext
context
)
{
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return
Scaffold
(
appBar:
AppBar
(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor:
Theme
.
of
(
context
).
colorScheme
.
inversePrimary
,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title:
Text
(
widget
.
title
),
),
body:
Column
(
...
...
lib/text_to_speech_page.dart
View file @
7421b5a0
...
...
@@ -107,14 +107,14 @@ class _TextToSpeechPageState extends State<TextToSpeechPage> {
Future
<
dynamic
>
_getEngines
()
async
=>
await
flutterTts
.
getEngines
;
Future
<
void
>
_getDefaultEngine
()
async
{
var
engine
=
await
flutterTts
.
getDefaultEngine
;
dynamic
engine
=
await
flutterTts
.
getDefaultEngine
;
if
(
engine
!=
null
)
{
print
(
engine
);
}
}
Future
<
void
>
_getDefaultVoice
()
async
{
var
voice
=
await
flutterTts
.
getDefaultVoice
;
dynamic
voice
=
await
flutterTts
.
getDefaultVoice
;
if
(
voice
!=
null
)
{
print
(
voice
);
}
...
...
@@ -233,20 +233,22 @@ class _TextToSpeechPageState extends State<TextToSpeechPage> {
}
else
return
const
Text
(
'Loading engines...'
);
});
}
else
}
else
{
return
Container
(
width:
0
,
height:
0
);
}
}
Widget
_futureBuilder
()
=>
FutureBuilder
<
dynamic
>(
future:
_getLanguages
(),
builder:
(
BuildContext
context
,
AsyncSnapshot
<
dynamic
>
snapshot
)
{
if
(
snapshot
.
hasData
)
{
return
_languageDropDownSection
(
snapshot
.
data
as
List
<
dynamic
>);
}
else
if
(
snapshot
.
hasError
)
{
return
const
Text
(
'Error loading languages...'
);
}
else
return
const
Text
(
'Loading Languages...'
);
});
future:
_getLanguages
(),
builder:
(
BuildContext
context
,
AsyncSnapshot
<
dynamic
>
snapshot
)
{
if
(
snapshot
.
hasData
)
{
return
_languageDropDownSection
(
snapshot
.
data
as
List
<
dynamic
>);
}
else
if
(
snapshot
.
hasError
)
{
return
const
Text
(
'Error loading languages...'
);
}
else
return
const
Text
(
'Loading Languages...'
);
},
);
Widget
_inputSection
()
=>
Container
(
alignment:
Alignment
.
topCenter
,
...
...
@@ -265,12 +267,27 @@ class _TextToSpeechPageState extends State<TextToSpeechPage> {
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
_buildButtonColumn
(
Colors
.
green
,
Colors
.
greenAccent
,
Icons
.
play_arrow
,
'PLAY'
,
_speak
),
_buildButtonColumn
(
Colors
.
red
,
Colors
.
redAccent
,
Icons
.
stop
,
'STOP'
,
_stop
),
Colors
.
green
,
Colors
.
greenAccent
,
Icons
.
play_arrow
,
'PLAY'
,
_speak
,
),
_buildButtonColumn
(
Colors
.
red
,
Colors
.
redAccent
,
Icons
.
stop
,
'STOP'
,
_stop
,
),
_buildButtonColumn
(
Colors
.
blue
,
Colors
.
blueAccent
,
Icons
.
pause
,
'PAUSE'
,
_pause
),
Colors
.
blue
,
Colors
.
blueAccent
,
Icons
.
pause
,
'PAUSE'
,
_pause
,
),
],
),
);
...
...
@@ -299,8 +316,13 @@ class _TextToSpeechPageState extends State<TextToSpeechPage> {
),
]));
Column
_buildButtonColumn
(
Color
color
,
Color
splashColor
,
IconData
icon
,
String
label
,
Function
func
)
{
Column
_buildButtonColumn
(
Color
color
,
Color
splashColor
,
IconData
icon
,
String
label
,
Function
func
,
)
{
return
Column
(
mainAxisSize:
MainAxisSize
.
min
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
...
...
lib/text_to_speech_util.dart
0 → 100644
View file @
7421b5a0
import
'package:flutter_tts/flutter_tts.dart'
;
class
TextToSpeechUtil
{
static
Future
<
void
>
speakTo
(
String
str
)
async
{
FlutterTts
flutterTts
=
FlutterTts
();
await
flutterTts
.
setVolume
(
1
);
await
flutterTts
.
setSpeechRate
(
0.5
);
await
flutterTts
.
setPitch
(
1
);
await
flutterTts
.
speak
(
str
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment