I am using android intent in flutter, and then want the app to go back to my app how to do it?

I have a project.

This project is need to have a feature that, when we clicked a button
the button will have a timer start, and then will go to another app. I have successfully done that, but the problem is. When the timer come off the another app should be back to my flutter app. I need help with this problem

Thank You.

This is my main_page.dart

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:wartel_lapas/core/widget/ButtonCustom.dart';
import 'package:wartel_lapas/core/widget/PageCustom.dart';
import 'package:wartel_lapas/pages/token_input_page.dart';

class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageCustom(
        padding: const EdgeInsets.only(
          top: 130,
          right: 18,
          left: 18,
        ),
        children: [
          SizedBox(
            height: 200,
            child: Image.asset(
              'assets/deltakode.png',
              fit: BoxFit.fill,
            ),
          ),
          const SizedBox(
            height: 30,
          ),
          Text(
            'Selamat datang!',
            softWrap: true,
            overflow: TextOverflow.clip,
            textAlign: TextAlign.center,
            style: GoogleFonts.plusJakartaSans(
              fontSize: 24,
              fontWeight: FontWeight.bold,
            ),
          ),
          const SizedBox(
            height: 15,
          ),
          Text(
            'Di Aplikasi Wartel Lapas Silahkan nKlik Tombol di Bawah Ini Untuk nMemulai',
            softWrap: true,
            overflow: TextOverflow.clip,
            textAlign: TextAlign.center,
            style: GoogleFonts.plusJakartaSans(
              fontSize: 16,
              fontWeight: FontWeight.w500,
            ),
          ),
          const SizedBox(
            height: 210,
          ),
          ButtonCustom(
            placeholder: 'Mulai!',
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => const TokenInputPage(),
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}

This is my token_input_dart.dart

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:wartel_lapas/core/widget/ButtonCustom.dart';
import 'package:wartel_lapas/core/widget/PageCustom.dart';
import 'package:wartel_lapas/pages/phone_input_page.dart';

class TokenInputPage extends StatefulWidget {
  const TokenInputPage({super.key});

  @override
  State<TokenInputPage> createState() => _TokenInputPageState();
}

class _TokenInputPageState extends State<TokenInputPage> {
  final _token = TextEditingController();
  int timeLeft = 5;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageCustom(
        padding: const EdgeInsets.only(top: 130, right: 16, left: 16),
        children: [
          SizedBox(
            height: 200,
            child: Image.asset(
              'assets/deltakode.png',
              fit: BoxFit.fill,
            ),
          ),
          const SizedBox(
            height: 30,
          ),
          Text(
            'Masukan Voucher Anda!',
            softWrap: true,
            overflow: TextOverflow.clip,
            textAlign: TextAlign.center,
            style: GoogleFonts.plusJakartaSans(
              fontSize: 24,
              fontWeight: FontWeight.bold,
            ),
          ),
          const SizedBox(
            height: 50,
          ),
          TextField(
            controller: _token,
            decoration: InputDecoration(
                labelText: 'Masukan Voucher',
                alignLabelWithHint: true,
                labelStyle: GoogleFonts.plusJakartaSans(fontSize: 16)),
            keyboardType: TextInputType.text,
          ),
          const SizedBox(
            height: 20,
          ),
          ButtonCustom(
            placeholder: 'Masuk',
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => PhoneInputPage(
                    timeLeft: timeLeft,
                  ),
                ),
              );
            },
          )
        ],
      ),
    );
  }
}

And this is my phone_input_page.dart

import 'dart:async';
// import 'package:android_intent/android_intent.dart';
import 'package:android_intent_plus/android_intent.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:wartel_lapas/core/widget/ButtonCustom.dart';
import 'package:wartel_lapas/core/widget/PageCustom.dart';

class PhoneInputPage extends StatefulWidget {
  const PhoneInputPage({super.key, this.timeLeft});

  final timeLeft; // Ensure timeLeft is passed as an integer (in seconds)

  @override
  State<PhoneInputPage> createState() => _PhoneInputPageState();
}

class _PhoneInputPageState extends State<PhoneInputPage> {
  final _phoneController = TextEditingController();
  bool isLoading = false;
  int? balanceAmount;
  String? transactionId;
  Timer? _timer;
  late int _remainingTime; // Countdown timer value

  @override
  void dispose() {
    _phoneController.dispose();
    _timer?.cancel();
    _closeVideoCall();
    super.dispose();
  }

  void _startCountdown() {
    _remainingTime = widget.timeLeft; // Initialize with the provided time
    _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      setState(() {
        if (_remainingTime > 0) {
          _remainingTime--;
        } else {
          _timer?.cancel();
          _closeVideoCall();
          Navigator.pop(context);
        }
      });
    });
  }

  void _closeVideoCall() async {
    print('Waktu Abis');
    ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(content: Text('Panggilan telah diakhiri.')),
    );
    // Bring the app back to the foreground
    // const intent = AndroidIntent(
    //   action: 'action_view',
    //   data: 'package:com.example.wartel_lapas',
    //   package: 'com.example.wartel_lapas',
    // );
    // await intent.launch();
    print('Balik');
  }

  String normalizePhoneNumber(String phone) {
    phone = phone.replaceAll(RegExp(r'D'), '');
    if (phone.startsWith('0')) {
      phone = '62${phone.substring(1)}';
    }
    if (!phone.startsWith('62')) {
      return ''; // Invalid format
    }
    return phone;
  }

  void _startVideoCall() async {
    setState(() {
      isLoading = true;
    });

    String normalizedPhone = normalizePhoneNumber(_phoneController.text);

    if (normalizedPhone.isEmpty) {
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(content: Text('Kode negara tidak ada atau salah.')),
      );
      setState(() {
        isLoading = false;
      });
      return;
    }

    _startCountdown();

    final intent = AndroidIntent(
      action: 'action_view',
      data: 'https://wa.me/$normalizedPhone',
      package: 'com.whatsapp',
    );
    await intent.launch();

    setState(() {
      isLoading = false;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageCustom(
        padding: const EdgeInsets.only(
          top: 130,
          right: 18,
          left: 18,
        ),
        children: [
          SizedBox(
            height: 200,
            child: Image.asset(
              'assets/deltakode.png',
              fit: BoxFit.fill,
            ),
          ),
          const SizedBox(
            height: 30,
          ),
          Text(
            'Masukan Nomor Telepon Yang Dituju!',
            softWrap: true,
            overflow: TextOverflow.clip,
            textAlign: TextAlign.center,
            style: GoogleFonts.plusJakartaSans(
              fontSize: 24,
              fontWeight: FontWeight.bold,
            ),
          ),
          const SizedBox(
            height: 30,
          ),
          Text(
            _timer == null
                ? 'Waktu Anda Tersedia: ${widget.timeLeft.toString()} detik'
                : 'Waktu Anda Sisa: $_remainingTime detik',
            style: GoogleFonts.plusJakartaSans(
              fontSize: 16,
              fontWeight: FontWeight.w700,
            ),
          ),
          TextField(
            controller: _phoneController,
            decoration: const InputDecoration(
              labelText: 'Nomor Telepon',
            ),
            keyboardType: TextInputType.phone,
          ),
          const SizedBox(
            height: 20,
          ),
          ButtonCustom(
            onPressed: isLoading ? null : _startVideoCall,
            placeholder:
                isLoading ? const CircularProgressIndicator() : 'Mulai Chat',
          ),
        ],
      ),
    );
  }
}

My package that im using is
cupertino_icons: ^1.0.6
google_fonts: ^6.2.1
android_intent_plus: ^5.2.0

How to get the second app back to my flutter app

Thank you

New contributor

Albani Zaidan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật