A small Flutter plugin that embeds the tawk.to chat widget. Works on web (DOM injection) and on mobile/desktop using a WebView.
import'package:flutter/material.dart';
import'package:tawk/tawk.dart';
voidmain() {
// Create a single controller with your Tawk.to chat URLfinal tawkController =TawkController(
chatUrl:'https://tawk.to/chat/YOUR_PROPERTY_ID/YOUR_WIDGET_ID',
);
runApp(ExampleApp(tawkController: tawkController));
}
classExampleAppextendsStatelessWidget {
finalTawkController tawkController;
constExampleApp({requiredthis.tawkController, super.key});
@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
title:'Tawk Example',
theme:ThemeData(primarySwatch:Colors.blue),
// Place TawkChat at the app root using MaterialApp.builder// This ensures the controller is available throughout the app
builder: (context, child) {
returnTawkChat(
controller: tawkController,
child: child ??constSizedBox.shrink(),
);
},
home:HomePage(),
);
}
}
classHomePageextendsStatelessWidget {
constHomePage({super.key});
@overrideWidgetbuild(BuildContext context) {
// Access the controller from anywhere in the appfinal controller =TawkController.of(context);
returnScaffold(
appBar:AppBar(title:constText('Tawk Example')),
body:Center(
child:ElevatedButton(
onPressed: () => controller.open(context),
child:constText('Open Tawk Chat'),
),
),
);
}
}dependencies:
tawk: ^0.1.0Or run:
flutter pub add tawk- Sign up at tawk.to and create a property
- Go to Administration → Chat Widget
- Copy your chat URL (format:
https://tawk.to/chat/PROPERTY_ID/WIDGET_ID)
import'package:tawk/tawk.dart';- Create a controller with your Tawk.to chat URL
- Place TawkChat at app root using
MaterialApp.builder - Open chat programmatically from anywhere using
controller.open(context)
See the Example app code above for a complete implementation.
TawkChat(
chatUrl:'https://tawk.to/chat/YOUR_PROPERTY_ID/YOUR_WIDGET_ID',
child:MyApp(),
)Stack(
children: [
MyApp(),
TawkChat(controller: tawkController),
],
)- Injects the official Tawk.to embed script into the document head
- Renders the standard floating chat widget (bottom-right corner)
- Uses
dart:js_interopfor efficient DOM manipulation - Supports both embedded and standalone modes
- Opens full-screen WebView with Tawk.to chat interface
- Uses
webview_flutterfor native platform integration - Automatic fallback to iframe if direct URL loading fails
- Optimized WebView settings for chat functionality
- Cross-platform: Web, iOS, Android
- Optimized performance: Simple URL parsing, efficient DOM injection, lightweight widget
- Flexible API: Controller-based or direct URL usage
- Security-focused: Minimal permissions, secure iframe attributes
- Modern Dart: Uses latest language features and best practices
// Create controllerfinal controller =TawkController(chatUrl:'https://tawk.to/chat/...');
// Open chat (mobile: opens WebView, web: activates existing widget)await controller.open(context);
// Close chat (mobile only, closes WebView)
controller.close(context);
// Check if chat is currently openfinal isOpen =await controller.isOpen();
// Access controller from widget treefinal controller =TawkController.of(context);// With controller (recommended)TawkChat(
controller: controller,
child:MyApp(), // optional
)
// Direct URL (creates internal controller)TawkChat(
chatUrl:'https://tawk.to/chat/...',
initialHeight:400, // web only, optional
child:MyApp(), // optional
)- Verify your chat URL format:
https://tawk.to/chat/PROPERTY_ID/WIDGET_ID - Check browser console for script loading errors
- Ensure TawkChat widget is in the widget tree
- Add
android:enableOnBackInvokedCallback="true"to your AndroidManifest.xml
- Ensure INTERNET permission is declared in AndroidManifest.xml
- Check that the chat URL is accessible from mobile browsers
- Provide your own Tawk.to chat URL and account
- Comply with Tawk.to's terms of service
- Follow applicable privacy laws (GDPR, CCPA, etc.)
- Update your privacy policy to mention Tawk.to integration
Contributions are welcome! Please:
- Fork the repository
- Create a new branch
- Add tests for new functionality
- Pass all CI checks
- Submit a pull request
📃 License
Every opened issue is very much appreciated!