flutter_chatwoot_sdk 1.0.1 flutter_chatwoot_sdk: ^1.0.1 copied to clipboard
A flutter client sdk for chatwoot. Integrate Chatwoot flutter client into your flutter app and talk to your visitors/users in real time.
import 'dart:io';
import 'package:flutter_chatwoot_sdk/chatwoot_sdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image/image.dart' as image;
import 'package:image_picker/image_picker.dart' as image_picker;
import 'package:path_provider/path_provider.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page',),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({required this.title});
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Chatwoot Example"),
),
body: ChatwootWidget(
websiteToken: "websiteToken",
baseUrl: "https://app.chatwoot.com",
user: ChatwootUser(
identifier: "test@test.com",
name: "Tester test",
email: "test@test.com",
),
locale: "en",
closeWidget: () {
if (Platform.isAndroid) {
SystemNavigator.pop();
} else if (Platform.isIOS) {
exit(0);
}
},
//attachment only works on android for now
onAttachFile: _androidFilePicker,
onLoadStarted: () {
print("loading widget");
},
onLoadProgress: (int progress) {
print("loading... ${progress}");
},
onLoadCompleted: () {
print("widget loaded");
},
),
);
}
Future<List<String>> _androidFilePicker() async {
final picker = image_picker.ImagePicker();
final photo =
await picker.pickImage(source: image_picker.ImageSource.gallery);
if (photo == null) {
return [];
}
final imageData = await photo.readAsBytes();
final decodedImage = image.decodeImage(imageData);
final scaledImage = image.copyResize(decodedImage!, width: 500);
final jpg = image.encodeJpg(scaledImage, quality: 90);
final filePath = (await getTemporaryDirectory()).uri.resolve(
'./image_${DateTime.now().microsecondsSinceEpoch}.jpg',
);
final file = await File.fromUri(filePath).create(recursive: true);
await file.writeAsBytes(jpg, flush: true);
return [file.uri.toString()];
}
}