Flutter – Redirection after clicking on deeplink not working despite getting the token

I’m struggling to make a redirection to my page for reinitializing a forgotten password.
i have a website, having the link “com-example-app://reinitialiser_mdp/token=dda8f861-fd89-492f-8d55-bf85e27743b0” on it (just for testing), and i want to redirect the user to the ReinitialisationPage, only if he click on a link that is valid and that contain a token (that is pre stored in my db).
but this code only open the app on the login page, despite having the token printed out :

Reloaded 14 of 1149 libraries in 1 410ms (compile: 172 ms, reload: 458 ms, reassemble: 568 ms).
I/flutter (18156): Received uri host: reinitialiser_mdp
I/flutter (18156): token : dda8f861-fd89-492f-8d55-bf85e27743b0

here is the main.dart :

void main() {
  runApp(
    ChangeNotifierProvider(
      create: (_) => UserProvider(),
      child: MyApp(),
    ),
  );
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String? _token;
  StreamSubscription<String?>? _linkSubscription;
  @override
  initState(){
    super.initState();
     _linkSubscription = linkStream.listen((String? linkStr) {
            if (linkStr != null) {
              Uri linkUri = Uri.parse(linkStr);
              print('Received uri host: ${linkUri.host}');
              if (linkUri.host == 'reinitialiser_mdp') {
                final tokenUri = linkUri.queryParameters['token'];
                if (tokenUri != null) {
                  print('token : $tokenUri');
                  setState(() {
                    _token = tokenUri;
                  });
                } else {
                  _token = null;
                }
              }
            }
          });
  }

  @override
  void dispose() {
    _linkSubscription?.cancel();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
   
    return MaterialApp(
      theme: ThemeData(
        colorScheme: ColorScheme.fromSwatch().copyWith(primary: const Color(0xFF008EFE)),
        useMaterial3: true,
      ),
      debugShowCheckedModeBanner: false,
      home: _token == null ? _buildHomePage() : ReinitialiserMdpPage(token: _token),
    );
  }

  Widget _buildHomePage() {
    final userProvider = Provider.of<UserProvider>(context);

    if (userProvider.user == null) {
      return const MyLoginPage();
    } else {
      return const MyHomePage();
    }
  }
}

and the reiMdp.dart :


void main() {
   runApp(
    ChangeNotifierProvider(
      create: (_) => UserProvider(),
      child: const MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        colorScheme: ColorScheme.fromSwatch().copyWith(primary: const Color(0xFF008EFE)),
        useMaterial3: true,
      ),
      debugShowCheckedModeBanner: false,
      home: const ReinitialiserMdpPage(),
    );
  }
}


class ReinitialiserMdpPage extends StatefulWidget {
  final String? token;
  const ReinitialiserMdpPage({super.key, this.token});


  @override
  ReinitialiserMdpPageState createState() => ReinitialiserMdpPageState();
}

class ReinitialiserMdpPageState extends State<ReinitialiserMdpPage> {
  late String? token;

  @override
  void initState() {
    super.initState();
    token = widget.token;
  }

  Future<bool> checkIfTokenInDB(token) async {
    if(token == null) {
      return false;
    }
    final response = await http.get(Uri.parse('${ApiConfig.baseUrl}/token/ifTokenInDb/$token'));
    if(response.statusCode == 200) {
      if(response.body == 'true') {
        print('token dans la bdd');
        return true;
      } else {
        print('token pas trouvé dans la bdd');
        return false;
      }
    } else {
      throw Exception('Erreur de chargement');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text('Page de réinitialisation du mot de passe'),
          Text('Token: $token'),
        ],
      ),
    );
    
  }
}

i tried a lot of thing but even chatgpt doesn’t know what to do.

New contributor

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

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