import 'package:flutter/material.dart'; import 'package:pshared/provider/resource.dart'; import 'package:pshared/service/account.dart'; import 'package:pshared/utils/exception.dart'; class EmailVerificationProvider extends ChangeNotifier { Resource _resource = Resource(data: null, isLoading: false); String? _token; Resource get resource => _resource; bool get isLoading => _resource.isLoading; bool get isSuccess => _resource.data == true; Exception? get error => _resource.error; Future verify(String token) async { final trimmed = token.trim(); if (trimmed.isEmpty) { _setResource( Resource( data: null, isLoading: false, error: Exception('Email verification token is empty.'), ), ); return; } if (_token == trimmed && _resource.isLoading) return; _token = trimmed; _setResource(Resource(data: null, isLoading: true)); try { await AccountService.verifyEmail(trimmed); _setResource(Resource(data: true, isLoading: false)); } catch (e) { _setResource( Resource( data: null, isLoading: false, error: toException(e), ), ); } } void _setResource(Resource resource) { _resource = resource; notifyListeners(); } }