import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_rating_bar/flutter_rating_bar.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Rate App Popup', theme: ThemeData( primarySwatch: Colors.blue, ), home: RateAppPage(), ); } } class RateAppPage extends StatefulWidget { @override _RateAppPageState createState() => _RateAppPageState(); } class _RateAppPageState extends State<RateAppPage> { Timer _timer; @override void initState() { super.initState(); _startTimer(); } @override void dispose() { _timer.cancel(); super.dispose(); } void _startTimer() { const duration = Duration(seconds: 30); _timer = Timer(duration, () { _showRateAppPopup(); }); } void _showRateAppPopup() { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text('Rate Our App'), content: Column( mainAxisSize: MainAxisSize.min, children: [ RatingBar.builder( initialRating: 0, minRating: 1, direction: Axis.horizontal, allowHalfRating: true, itemCount: 5, itemPadding: EdgeInsets.symmetric(horizontal: 4.0), itemBuilder: (context, _) => Icon( Icons.star, color: Colors.amber, ), onRatingUpdate: (rating) { print(rating); // Handle the rating, you can save it or send it to your backend. }, ), SizedBox(height: 16), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ FlatButton( onPressed: () { Navigator.of(context).pop(); }, child: Text('Cancel'), ), FlatButton( onPressed: () { // Handle rate action Navigator.of(context).pop(); }, child: Text('Rate'), ), FlatButton( onPressed: () { // Handle later action Navigator.of(context).pop(); }, child: Text('Later'), ), ], ), ], ), ); }, ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Rate App Popup Example'), ), body: Center( child: Text( 'Welcome to our app!', style: TextStyle(fontSize: 20), ), ), ); } }