Hi Team, our organisation is using Growthbook wit...
# sdk-flutter
s
Hi Team, our organisation is using Growthbook with streamline features, but we are facing starting trouble, If we pass backgroundSync: true, it takes lot of time to load the page and screen goes blank, I have to pass it as false first and later we have to pass it as true then only it works. This is my code snnippet, can someone help me to resolve this. gb = await GBSDKBuilderApp( hostURL: "", apiKey: "", growthBookTrackingCallBack: (exp, rst) {}, backgroundSync: true, ).setRefreshHandler((updated) { if (updated) { _fetchFeatureData(); } }).initialize(); await gb?.refresh().whenComplete(() => print(gb?.features().keys)); }
c
Hi, @strong-gold-58160. Yes, sure. Please let us check that and we will write to you.
Hi, @strong-gold-58160. What are you doing in this function
_fetchFeatureData()
before initialization?
s
take this import 'dart:async'; import 'package:flutter/material.dart'; import 'package:growthbook_sdk_flutter/growthbook_sdk_flutter.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( darkTheme: ThemeData.dark(), themeMode: ThemeMode.dark, home: const FeatureStreamWidget(), ); } } class FeatureStreamWidget extends StatefulWidget { const FeatureStreamWidget({super.key}); @override _FeatureStreamWidgetState createState() => _FeatureStreamWidgetState(); } class _FeatureStreamWidgetState extends State<FeatureStreamWidget> { GrowthBookSDK? gb; late StreamController<Map<String, dynamic>> _streamController; void initState() { super.initState(); _streamController = StreamController<Map<String, dynamic>>(); initializeSDK(); } void initializeSDK() async { gb = await GBSDKBuilderApp( hostURL: ''', apiKey: "", rdt-notification-date growthBookTrackingCallBack: (exp, rst) {}, backgroundSync: true, ).setRefreshHandler((updated) { if (updated) { _fetchFeatureData(); } }).initialize(); await gb?.refresh().whenComplete(() => print(gb?.features().keys)); //await gb?.refreshCache().whenComplete(() => print(gb?.getFeatures().keys)); } void _fetchFeatureData() async { final feature = gb?.feature('rdt-notification-date').value; print('//feature value = $feature'); _streamController.add(feature); } @override Widget build(BuildContext context) { return MaterialApp( home: StreamBuilder<Map<String, dynamic>>( stream: _streamController.stream, builder: (BuildContext context, AsyncSnapshot<Map<String, dynamic>> snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center( child: CircularProgressIndicator(), ); } else if (snapshot.hasError) { return Center( child: Text('Error: ${snapshot.error}'), ); } else if (snapshot.hasData) { Map<String, dynamic> featureData = snapshot.data!; return Center( child: Text( 'Feature data: ${featureData.toString()}', style: const TextStyle(color: Colors.black), ), ); } else { return const Center( child: Text('No data available.'), ); } }, ), ); } @override void dispose() { _streamController.close(); super.dispose(); } }
🙌 1
This is my complete code
c
Thank you. Let us check the code.
❤️ 1
s
we should get growth book response first, then it has to start streamline, but in current version, it starts streaming and then makes application load delay.
👍 1
one way we could able to fix is, make backgroundSync: false, and then with timer execution we will make it to true.
c
Hi, @strong-gold-58160. Thank you. We found the issue and have fixed it. The new version 3.9.8 has been released.
❤️ 1