Closed mendelg closed 1 year ago
The bug To avoid the dialog from appearing we can call:
await rateMyApp.callEvent(RateMyAppEventType.rateButtonPressed);
However, despite calling it in my code, the dialog still appears after doing a Hot Restart.
My code;
TextButton( child: Text('OK'), onPressed: () async { stars = stars ?? 0; if (stars! < 4) { Navigator.of(context, rootNavigator: true).pop(); // --> I'm calling this here, so the dialog shouldn't appear again. await _rateMyApp .callEvent(RateMyAppEventType.rateButtonPressed); )
Complete code (not really runnable)
import 'package:expansion_tile_card/expansion_tile_card.dart'; import 'package:flutter/material.dart'; import 'package:hive/hive.dart'; import 'package:hive_flutter/adapters.dart'; import 'package:mishnayos_project/widgets/expansion_tile_card.dart'; import 'package:mishnayos_project/models/word.dart'; import 'package:mishnayos_project/providers/api_service.dart'; import 'package:rate_my_app/rate_my_app.dart'; import '../constants/colors.dart'; class HomeScreen extends StatefulWidget { const HomeScreen({Key? key}) : super(key: key); @override State<HomeScreen> createState() => _HomeScreenState(); } class _HomeScreenState extends State<HomeScreen> { var isLoaded = false; late Box<Word> wordBox; late Box<Word> favoritesBox; late Box<String> lastRefreshedBox; final _scrollController = ScrollController(); final _rateMyApp = RateMyApp( preferencesPrefix: 'rateMyApp_', minDays: 0, minLaunches: 0, remindDays: 2, remindLaunches: 3, googlePlayIdentifier: 'com.mendelg.otzar_roshei_teivot2', appStoreIdentifier: "6444920898", ); @override Widget build(BuildContext context) { return Scaffold( backgroundColor: KscaffoldBackgroundColor, body: SafeArea( child: RefreshIndicator( color: Theme.of(context).primaryColor, onRefresh: () async { await _onRefresh(); }, child: Scrollbar( thickness: 5, controller: _scrollController, isAlwaysShown: true, child: ListView.builder( controller: _scrollController, physics: AlwaysScrollableScrollPhysics(), itemBuilder: (context, index) { return ValueListenableBuilder( valueListenable: Hive.box<Word>('words').listenable(), builder: (context, Box<Word> words, _) { final word = words.getAt(index); if (index == 0) { return Column( children: [ Text( "Pull down to refresh", style: TextStyle( color: Colors.blueGrey, fontSize: 18), ), _buildExpansionTileCard(word!) ], ); } return _buildExpansionTileCard(word!); }); }, itemCount: wordBox.length), )))); } @override void initState() { super.initState(); wordBox = Hive.box<Word>("words"); favoritesBox = Hive.box<Word>("favorites"); lastRefreshedBox = Hive.box<String>("lastRefreshed"); _rateMyApp.init().then((_) { _rateMyApp.showStarRateDialog( context, title: 'Enjoying Otzar Roshei Teivot?', message: 'Please leave a rating!\n it really helps us out!', actionsBuilder: (_, stars) { return [ TextButton( child: Text('OK'), onPressed: () async { stars = stars ?? 0; if (stars! < 4) { Navigator.of(context, rootNavigator: true).pop(); await _rateMyApp .callEvent(RateMyAppEventType.rateButtonPressed); } else { Navigator.of(context, rootNavigator: true).pop(); await _rateMyApp .callEvent(RateMyAppEventType.rateButtonPressed); if (await _rateMyApp.isNativeReviewDialogSupported == false) { await _rateMyApp.launchNativeReviewDialog(); } else { await _rateMyApp.launchStore(); } } }, ), ]; }, ignoreNativeDialog: true, starRatingOptions: StarRatingOptions(), onDismissed: () => _rateMyApp.callEvent(RateMyAppEventType.laterButtonPressed), ); }); } dispose() { _scrollController.dispose(); super.dispose(); } }
Expected behavior The expected behavior should be that the dialog shouldn't appear, since I have mimicked a rateButtonPressed event.
rateButtonPressed
Note I think the problem might be with the way I'm dismissing the Dialog, I'm using:
Navigator.of(context, rootNavigator: true).pop();
Instead of:
Navigator.pop<RateMyAppDialogButton>(context, RateMyAppDialogButton.rate);
But I'm using Navigator.of(context, rootNavigator: true).pop() since Popping the other way is popping my BottomNavigationBar, and it isn't popping the RatingBar.
Navigator.of(context, rootNavigator: true).pop()
Okay, here was the problem:I forgot to call:
_rateMyApp.shouldOpenDialog As the name implies, this checks whether the dialog is meant to be opened. But I was calling the dialog no matter what.
_rateMyApp.shouldOpenDialog
The bug To avoid the dialog from appearing we can call:
However, despite calling it in my code, the dialog still appears after doing a Hot Restart.
My code;
Complete code (not really runnable)
Expected behavior The expected behavior should be that the dialog shouldn't appear, since I have mimicked a
rateButtonPressed
event.Note I think the problem might be with the way I'm dismissing the Dialog, I'm using:
Instead of:
But I'm using
Navigator.of(context, rootNavigator: true).pop()
since Popping the other way is popping my BottomNavigationBar, and it isn't popping the RatingBar.