talkplus_flutter_sdk 0.4.7 talkplus_flutter_sdk: ^0.4.7 copied to clipboard
TalkPlus Flutter SDK
import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:talkplus_flutter_sdk/entity/channel/TPChannel.dart';
import 'package:talkplus_flutter_sdk/entity/channel/TPMessage.dart';
import 'package:talkplus_flutter_sdk/entity/user/TPUser.dart';
import 'package:talkplus_flutter_sdk/talkplus_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
// final _talkplusFlutterSdkPlugin = TalkplusFlutterSdk();
@override
void initState() {
super.initState();
initPlatformState();
}
TPChannel? channel;
void test() async {
await TalkPlusAPI.init("3ee30362-8459-4ff8-b69c-091be04cfd7a");
TPUser? user =
await TalkPlusAPI.loginAnonymous("userId", "제임스", null, null);
channel = await TalkPlusAPI.joinChannel("demo_channel");
debugPrint("channel: ${channel?.getChannelId()}");
List<TPMessage>? messages =
await TalkPlusAPI.getMessageList(channel!, null);
for (TPMessage message in messages!) {
debugPrint(
"message: ${message.getMessageId()} ${message.getMentions()} ${message.getParentMessage()} ${message.getReactions()}");
}
// TPMessage? message = await TalkPlusAPI.sendMessage(
// channel!, "테스트", TPMessage.TYPE_TEXT, null, null, null);
// TPMessage? message2 = await TalkPlusAPI.sendMessage(
// channel!, "테스트2", TPMessage.TYPE_TEXT, ["cf04-bc95-6be1", "820a-8d06-17af"], message?.getMessageId(), null);
//
// await TalkPlusAPI.addMessageReaction(message2!, "happy");
// File file =
// await TalkPlusAPI.sendFileMessage(channel, null, TPMessage.TYPE_TEXT, file, null);
}
XFile? image;
final ImagePicker picker = ImagePicker();
void uploadPhoto() async {
debugPrint("uploadPhoto");
var img = await picker.pickImage(source: ImageSource.gallery);
image = img;
String path = "${image?.path}";
debugPrint("path: $path");
if (image?.path != null) {
File file = File(path);
try {
TPMessage? message = await TalkPlusAPI.sendFileMessage(
channel!, "", TPMessage.TYPE_TEXT, file, null, null, null);
debugPrint("sendFileMessage success: ${message?.getMessageId()}");
} catch (err) {
debugPrint("sendFileMessage err: $err");
}
}
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
// TalkPlusAPI.init(appId);
// platformVersion =
// await _talkplusFlutterSdkPlugin.getPlatformVersion() ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
test();
// uploadPhoto();
},
child: Text('Upload Photo'),
),
),
),
);
}
}