Commit 3ffbc5c4 authored by Gavin An's avatar Gavin An

test

parent 2e705874
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class FireStoreTestPage extends StatefulWidget {
const FireStoreTestPage({super.key});
@override
State<FireStoreTestPage> createState() => _FireStoreTestPageState();
}
class _FireStoreTestPageState extends State<FireStoreTestPage> {
final FirebaseFirestore store = FirebaseFirestore.instance;
late Stream<QuerySnapshot<Map<String, dynamic>>> querySnapShot;
@override
void initState() {
super.initState();
querySnapShot =
store.collection('baecha')
// .where('baljuGroupId', whereIn: ['baecha_group_001', 'baecha_group_002'])
.snapshots();
}
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: querySnapShot,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const CircularProgressIndicator();
}
List<QueryDocumentSnapshot<Map<String, dynamic>>> documents = snapshot.data!.docs;
return Expanded(
child: ListView.builder(
shrinkWrap: true,
reverse: true,
itemCount: documents.length,
itemBuilder: (context, index) {
final item = documents[index];
String id = item.id;
String groupId = item['baljuGroupId'];
String createDate = item['createDate'];
int callCnt = item['callCnt'];
int passCnt = item['passCnt'];
return Container(
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
decoration: BoxDecoration(
color: Colors.amber,
border: Border.all(color: Colors.black, width: 1),
borderRadius: const BorderRadius.all(Radius.circular(20)),
),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('id: $id'),
Text('groupId: $groupId'),
Text('createDate: $createDate'),
Text('callCnt: ${callCnt.toString()}'),
Text('passCnt: ${passCnt.toString()}'),
],
),
);
},
),
);
},
);
}
}
import 'dart:math'; import 'dart:math';
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:dispatcher_test/fire_store_test_page.dart';
import 'package:dispatcher_test/firebase_options.dart'; import 'package:dispatcher_test/firebase_options.dart';
import 'package:dispatcher_test/module/dependency_inject.dart'; import 'package:dispatcher_test/module/dependency_inject.dart';
import 'package:dispatcher_test/notification_page.dart'; import 'package:dispatcher_test/notification_page.dart';
...@@ -15,6 +16,7 @@ import 'package:flutter/services.dart'; ...@@ -15,6 +16,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart'; import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:uuid/uuid.dart';
const List<String> sample = [ const List<String> sample = [
'배고프다', '배고프다',
...@@ -77,8 +79,7 @@ Future<void> setupFlutterNotifications() async { ...@@ -77,8 +79,7 @@ Future<void> setupFlutterNotifications() async {
channel = const AndroidNotificationChannel( channel = const AndroidNotificationChannel(
'high_importance_channel', // id 'high_importance_channel', // id
'High Importance Notifications', // title 'High Importance Notifications', // title
description: description: 'This channel is used for important notifications.', // description
'This channel is used for important notifications.', // description
importance: Importance.high, importance: Importance.high,
); );
...@@ -89,8 +90,7 @@ Future<void> setupFlutterNotifications() async { ...@@ -89,8 +90,7 @@ Future<void> setupFlutterNotifications() async {
/// We use this channel in the `AndroidManifest.xml` file to override the /// We use this channel in the `AndroidManifest.xml` file to override the
/// default FCM channel to enable heads up notifications. /// default FCM channel to enable heads up notifications.
await flutterLocalNotificationsPlugin await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation< .resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel); ?.createNotificationChannel(channel);
/// Update the iOS foreground notification presentation options to allow /// Update the iOS foreground notification presentation options to allow
...@@ -108,12 +108,11 @@ void main() async { ...@@ -108,12 +108,11 @@ void main() async {
dependenciesInitialized(); dependenciesInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
// FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseFirestore.instance.settings = const Settings( FirebaseFirestore.instance.settings = const Settings(
persistenceEnabled: true, persistenceEnabled: true,
); );
// TODO 카카오 Login // TODO 카카오 Login init
// KakaoSdk.init( // KakaoSdk.init(
// nativeAppKey: '' // nativeAppKey: ''
// ); // );
...@@ -178,111 +177,141 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -178,111 +177,141 @@ class _MyHomePageState extends State<MyHomePage> {
), ),
body: Column( body: Column(
children: [ children: [
TextButton( // TextButton(
style: const ButtonStyle( // style: const ButtonStyle(
backgroundColor: WidgetStatePropertyAll(Colors.amber), // backgroundColor: WidgetStatePropertyAll(Colors.amber),
minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))), // minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))),
onPressed: () { // onPressed: () {
Navigator.push( // Navigator.push(
context, // context,
MaterialPageRoute( // MaterialPageRoute(
builder: (context) => const SpeechToTextPage(), // builder: (context) => const SpeechToTextPage(),
)); // ));
}, // },
child: const Text( // child: const Text(
'음성입력', // '음성입력',
style: TextStyle(color: Colors.black), // style: TextStyle(color: Colors.black),
), // ),
), // ),
// const SizedBox(
// height: 10,
// ),
// TextButton(
// style: const ButtonStyle(
// backgroundColor: WidgetStatePropertyAll(Colors.amber),
// minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))),
// onPressed: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => const TextToSpeechPage(),
// ));
// },
// child: const Text(
// '음성변환',
// style: TextStyle(color: Colors.black),
// ),
// ),
// const SizedBox(
// height: 10,
// ),
// TextButton(
// style: const ButtonStyle(
// backgroundColor: WidgetStatePropertyAll(Colors.amber),
// minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))),
// onPressed: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => const GenerateNotificationPage(),
// ));
// },
// child: const Text(
// '알림입력',
// style: TextStyle(color: Colors.black),
// ),
// ),
// TextButton(
// style: const ButtonStyle(
// backgroundColor: WidgetStatePropertyAll(Colors.amber),
// minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))),
// onPressed: () async {
// // bool talkInstalled = await isKakaoTalkInstalled();
// // if (talkInstalled) {
// try {
// OAuthToken token =
// await UserApi.instance.loginWithKakaoAccount();
// // TODO 서버에 토큰 올린 후, response 에 따라 회원가입 절차
// return;
// } catch (e) {
// print('카카오톡으로 로그인 실패 $e');
// // 사용자가 카카오톡 설치 후 디바이스 권한 요청 화면에서 로그인을 취소한 경우,
// // 의도적인 로그인 취소로 보고 카카오계정으로 로그인 시도 없이 로그인 취소로 처리 (예: 뒤로 가기)
// if (e is PlatformException && e.code == 'CANCELED') {
// return;
// }
// }
// // }
// // 카카오톡 계정이 없거나, 카카오톡 설치가 되지 않았다면 웹으로 로그인
// OAuthToken token = await UserApi.instance.loginWithKakaoAccount();
// // TODO 서버에 토큰 올린 후, response 에 따라 회원가입 절차
// },
// child: Text('카카오로그인', style: const TextStyle(color: Colors.black)),
// ),
const SizedBox( const SizedBox(
height: 10, height: 10,
), ),
TextButton( const FireStoreTestPage(),
style: const ButtonStyle(
backgroundColor: WidgetStatePropertyAll(Colors.amber),
minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const TextToSpeechPage(),
));
},
child: const Text(
'음성변환',
style: TextStyle(color: Colors.black),
),
),
const SizedBox( const SizedBox(
height: 10, height: 80,
), ),
TextButton( ],
style: const ButtonStyle( ),
backgroundColor: WidgetStatePropertyAll(Colors.amber), floatingActionButton: Row(
minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))), crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: [
// IconButton(onPressed: () {}, icon: Icon(Icons.add)),
// IconButton(onPressed: () {}, icon: Icon(Icons.mic)),
FloatingActionButton(
tooltip: 'Increment',
child: const Icon(Icons.add),
onPressed: () { onPressed: () {
Navigator.push( Random rd = Random();
context, int rdNum = rd.nextInt(10);
MaterialPageRoute( int callNum = rd.nextInt(20);
builder: (context) => const GenerateNotificationPage(), int passNum = rd.nextInt(15);
)); int minRan = rd.nextInt(30);
}, DateTime dt = DateTime.now().add(Duration(minutes: minRan));
child: const Text( // String rdStr = sample[rdNum];
'알림입력', var uuid = const Uuid();
style: TextStyle(color: Colors.black), String baljuGroupId = 'baecha_group_00$rdNum';
), store.collection('baecha').doc(uuid.v4()).set({
), 'baljuGroupId': baljuGroupId,
TextButton( 'callCnt': callNum,
style: const ButtonStyle( 'passCnt': passNum,
backgroundColor: WidgetStatePropertyAll(Colors.amber), 'createDate': dt.toIso8601String(),
minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))), });
onPressed: () async {
// bool talkInstalled = await isKakaoTalkInstalled();
// if (talkInstalled) {
try {
OAuthToken token =
await UserApi.instance.loginWithKakaoAccount();
// TODO 서버에 토큰 올린 후, response 에 따라 회원가입 절차
return;
} catch (e) {
print('카카오톡으로 로그인 실패 $e');
// 사용자가 카카오톡 설치 후 디바이스 권한 요청 화면에서 로그인을 취소한 경우,
// 의도적인 로그인 취소로 보고 카카오계정으로 로그인 시도 없이 로그인 취소로 처리 (예: 뒤로 가기)
if (e is PlatformException && e.code == 'CANCELED') {
return;
}
}
// }
// 카카오톡 계정이 없거나, 카카오톡 설치가 되지 않았다면 웹으로 로그인
OAuthToken token = await UserApi.instance.loginWithKakaoAccount();
// TODO 서버에 토큰 올린 후, response 에 따라 회원가입 절차
}, },
child: Text('카카오로그인', style: const TextStyle(color: Colors.black)),
), ),
const SizedBox( const SizedBox(
height: 10, width: 30,
), ),
Center( FloatingActionButton(
// Center is a layout widget. It takes a single child and positions it tooltip: 'Modify',
// in the middle of the parent. child: const Icon(Icons.published_with_changes),
child: StreamBuilder( onPressed: () async {
stream: store.collection('test').doc('chat').snapshots(), // store.collection('baecha').doc().
builder: (context, snapshot) { Random rd = Random();
String field = snapshot.data?.get('msg') ?? ''; int rdNum = rd.nextInt(20);
return Center(child: Text(field)); int rdNum2 = rd.nextInt(30);
// String rdStr = sample[rdNum];
QuerySnapshot<Map<String, dynamic>> firstDoc = await store.collection('baecha').get();
String firstId = firstDoc.docs[firstDoc.docs.length - 1].id ?? '';
store.collection('baecha').doc(firstId).update({'callCnt': rdNum, 'passCnt': rdNum2});
}, },
)) ),
], ],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Random rd = Random();
int rdNum = rd.nextInt(6);
String rdStr = sample[rdNum];
store.collection('test').doc('chat').set({"msg": rdStr});
},
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods. ), // This trailing comma makes auto-formatting nicer for build methods.
); );
} }
......
...@@ -28,7 +28,7 @@ class _SpeechToTextPageState extends State<SpeechToTextPage> { ...@@ -28,7 +28,7 @@ class _SpeechToTextPageState extends State<SpeechToTextPage> {
/// Each time to start a speech recognition session /// Each time to start a speech recognition session
void _startListening() async { void _startListening() async {
await _speechToText.listen(onResult: _onSpeechResult); await _speechToText.listen(onResult: _onSpeechResultListener);
setState(() {}); setState(() {});
} }
...@@ -43,7 +43,8 @@ class _SpeechToTextPageState extends State<SpeechToTextPage> { ...@@ -43,7 +43,8 @@ class _SpeechToTextPageState extends State<SpeechToTextPage> {
/// This is the callback that the SpeechToText plugin calls when /// This is the callback that the SpeechToText plugin calls when
/// the platform returns recognized words. /// the platform returns recognized words.
void _onSpeechResult(SpeechRecognitionResult result) { void _onSpeechResultListener(SpeechRecognitionResult result) {
print('isFinal: ${result.finalResult}');
_lastWords = result.recognizedWords; _lastWords = result.recognizedWords;
setState(() {}); setState(() {});
} }
......
...@@ -761,10 +761,10 @@ packages: ...@@ -761,10 +761,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: uuid name: uuid
sha256: "83d37c7ad7aaf9aa8e275490669535c8080377cfa7a7004c24dfac53afffaa90" sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.4.2" version: "4.5.1"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
...@@ -777,10 +777,10 @@ packages: ...@@ -777,10 +777,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: vm_service name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "14.2.4" version: "14.2.5"
web: web:
dependency: transitive dependency: transitive
description: description:
......
...@@ -44,6 +44,8 @@ dependencies: ...@@ -44,6 +44,8 @@ dependencies:
firebase_messaging: ^15.0.4 firebase_messaging: ^15.0.4
kakao_flutter_sdk_user: ^1.9.5 # 카카오 로그인 API 패키지 kakao_flutter_sdk_user: ^1.9.5 # 카카오 로그인 API 패키지
uuid: ^4.5.1
# inversion of control(service locator) # inversion of control(service locator)
get_it: ^7.7.0 get_it: ^7.7.0
...@@ -52,8 +54,6 @@ dependencies: ...@@ -52,8 +54,6 @@ dependencies:
pretty_dio_logger: ^1.4.0 pretty_dio_logger: ^1.4.0
fluttertoast: ^8.2.8 fluttertoast: ^8.2.8
uuid: ^4.4.2
# secure storage # secure storage
flutter_secure_storage: ^9.2.2 flutter_secure_storage: ^9.2.2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment