// YetiPoll for Flutter. Add this file to your project. // // pubspec.yaml: webview_flutter and url_launcher // // Navigator.push(context, MaterialPageRoute( // builder: (_) => YetiPollWall(appKey: 'yp_live_pk_...', userId: user.id))); // // Pass `signature` when your app requires signed wall links: compute it on // your server (HMAC-SHA256 of the user id with your secret key). import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:webview_flutter/webview_flutter.dart'; Uri yetiPollWallUrl({required String appKey, required String userId, String? signature}) { return Uri.https('yetipoll.com', '/wall', { 'app': appKey, 'user': userId, if (signature != null && signature.isNotEmpty) 'sig': signature, }); } class YetiPollWall extends StatefulWidget { const YetiPollWall({super.key, required this.appKey, required this.userId, this.signature}); final String appKey; final String userId; final String? signature; @override State createState() => _YetiPollWallState(); } class _YetiPollWallState extends State with WidgetsBindingObserver { late final WebViewController _controller; @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); _controller = WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) ..setNavigationDelegate(NavigationDelegate( // The wall stays in the app; surveys open in the user's browser. onNavigationRequest: (request) { final uri = Uri.parse(request.url); final onWall = uri.host == 'yetipoll.com' && !uri.path.startsWith('/wall/go/'); if (onWall) return NavigationDecision.navigate; launchUrl(uri, mode: LaunchMode.externalApplication); return NavigationDecision.prevent; }, )) ..loadRequest(yetiPollWallUrl(appKey: widget.appKey, userId: widget.userId, signature: widget.signature)); } // Fresh surveys when the user comes back from one. @override void didChangeAppLifecycleState(AppLifecycleState state) { if (state == AppLifecycleState.resumed) _controller.reload(); } @override void dispose() { WidgetsBinding.instance.removeObserver(this); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Surveys')), body: WebViewWidget(controller: _controller), ); } }