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 '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/module/dependency_inject.dart';
import 'package:dispatcher_test/notification_page.dart';
......@@ -15,6 +16,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:uuid/uuid.dart';
const List<String> sample = [
'배고프다',
......@@ -77,8 +79,7 @@ Future<void> setupFlutterNotifications() async {
channel = const AndroidNotificationChannel(
'high_importance_channel', // id
'High Importance Notifications', // title
description:
'This channel is used for important notifications.', // description
description: 'This channel is used for important notifications.', // description
importance: Importance.high,
);
......@@ -89,8 +90,7 @@ Future<void> setupFlutterNotifications() async {
/// We use this channel in the `AndroidManifest.xml` file to override the
/// default FCM channel to enable heads up notifications.
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
/// Update the iOS foreground notification presentation options to allow
......@@ -108,12 +108,11 @@ void main() async {
dependenciesInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
// FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseFirestore.instance.settings = const Settings(
persistenceEnabled: true,
);
// TODO 카카오 Login
// TODO 카카오 Login init
// KakaoSdk.init(
// nativeAppKey: ''
// );
......@@ -178,111 +177,141 @@ class _MyHomePageState extends State<MyHomePage> {
),
body: Column(
children: [
TextButton(
style: const ButtonStyle(
backgroundColor: WidgetStatePropertyAll(Colors.amber),
minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SpeechToTextPage(),
));
},
child: const Text(
'음성입력',
style: TextStyle(color: Colors.black),
),
),
// TextButton(
// style: const ButtonStyle(
// backgroundColor: WidgetStatePropertyAll(Colors.amber),
// minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))),
// onPressed: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => const SpeechToTextPage(),
// ));
// },
// 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 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(
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 FireStoreTestPage(),
const SizedBox(
height: 10,
height: 80,
),
],
),
TextButton(
style: const ButtonStyle(
backgroundColor: WidgetStatePropertyAll(Colors.amber),
minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))),
floatingActionButton: Row(
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: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const GenerateNotificationPage(),
));
Random rd = Random();
int rdNum = rd.nextInt(10);
int callNum = rd.nextInt(20);
int passNum = rd.nextInt(15);
int minRan = rd.nextInt(30);
DateTime dt = DateTime.now().add(Duration(minutes: minRan));
// String rdStr = sample[rdNum];
var uuid = const Uuid();
String baljuGroupId = 'baecha_group_00$rdNum';
store.collection('baecha').doc(uuid.v4()).set({
'baljuGroupId': baljuGroupId,
'callCnt': callNum,
'passCnt': passNum,
'createDate': dt.toIso8601String(),
});
},
child: const Text(
'알림입력',
style: TextStyle(color: Colors.black),
),
const SizedBox(
width: 30,
),
TextButton(
style: const ButtonStyle(
backgroundColor: WidgetStatePropertyAll(Colors.amber),
minimumSize: WidgetStatePropertyAll(Size.fromHeight(30))),
FloatingActionButton(
tooltip: 'Modify',
child: const Icon(Icons.published_with_changes),
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 에 따라 회원가입 절차
// store.collection('baecha').doc().
Random rd = Random();
int rdNum = rd.nextInt(20);
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});
},
child: Text('카카오로그인', style: const TextStyle(color: Colors.black)),
),
const SizedBox(
height: 10,
),
Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: StreamBuilder(
stream: store.collection('test').doc('chat').snapshots(),
builder: (context, snapshot) {
String field = snapshot.data?.get('msg') ?? '';
return Center(child: Text(field));
},
))
],
),
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.
);
}
......
......@@ -28,7 +28,7 @@ class _SpeechToTextPageState extends State<SpeechToTextPage> {
/// Each time to start a speech recognition session
void _startListening() async {
await _speechToText.listen(onResult: _onSpeechResult);
await _speechToText.listen(onResult: _onSpeechResultListener);
setState(() {});
}
......@@ -43,7 +43,8 @@ class _SpeechToTextPageState extends State<SpeechToTextPage> {
/// This is the callback that the SpeechToText plugin calls when
/// the platform returns recognized words.
void _onSpeechResult(SpeechRecognitionResult result) {
void _onSpeechResultListener(SpeechRecognitionResult result) {
print('isFinal: ${result.finalResult}');
_lastWords = result.recognizedWords;
setState(() {});
}
......
......@@ -761,10 +761,10 @@ packages:
dependency: "direct main"
description:
name: uuid
sha256: "83d37c7ad7aaf9aa8e275490669535c8080377cfa7a7004c24dfac53afffaa90"
sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff
url: "https://pub.dev"
source: hosted
version: "4.4.2"
version: "4.5.1"
vector_math:
dependency: transitive
description:
......@@ -777,10 +777,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.2.5"
web:
dependency: transitive
description:
......
......@@ -44,6 +44,8 @@ dependencies:
firebase_messaging: ^15.0.4
kakao_flutter_sdk_user: ^1.9.5 # 카카오 로그인 API 패키지
uuid: ^4.5.1
# inversion of control(service locator)
get_it: ^7.7.0
......@@ -52,8 +54,6 @@ dependencies:
pretty_dio_logger: ^1.4.0
fluttertoast: ^8.2.8
uuid: ^4.4.2
# secure storage
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