Commit 1046369
authored
Implement retry logic (#69)
# 🔄 Add Manual Retry Functionality with Exponential Backoff
## 📋 Summary
This PR adds a manual retry mechanism to the `OfflineBuilder` widget,
allowing users to trigger connectivity checks with exponential backoff.
This enhancement provides better control over network status
verification, particularly useful when automatic connectivity detection
may be delayed or when users want to force a re-check.
## ✨ Key Features
- **Manual Retry Method**: New `retry()` method allows manual triggering
of connectivity checks
- **Exponential Backoff**: Uses 2^n seconds strategy (1s, 2s, 4s, 8s,
16s) with configurable max retries (default: 5)
- **Smart Protection**: Cooldown between retries (default: 2 seconds)
prevents spam
- **State Management**: New `onBuilderReady` callback provides access to
retry state and methods
- **Custom Callbacks**: Optional `onRetry` callback for custom logic
during retry attempts
- **State Properties**: Exposes `canRetry`, `isRetrying`, and
`retryCount` for UI control
- **Auto Reset**: Retry counter automatically resets when connection is
restored
## 🔧 API Changes
Added optional parameters to `OfflineBuilder`:
- `maxRetries` - Maximum retry attempts (default: 5)
- `retryCooldown` - Cooldown duration between retries (default: 2
seconds)
- `onRetry` - Custom callback executed during retry
- `onBuilderReady` - Callback providing access to `OfflineBuilderState`
Added public properties to `OfflineBuilderState`:
- `canRetry` - Boolean indicating if retry is available
- `isRetrying` - Boolean indicating if retry is in progress
- `retryCount` - Current number of retry attempts
- `retry()` - Method to trigger manual retry
## 🧪 Testing
- ✅ All 29 tests pass (23 existing + 6 new)
- ✅ New tests cover retry parameters, callbacks, max limits, and counter
behaviour
- ✅ Fully backward compatible with existing implementations
## 🔄 Backward Compatibility
✅ **100% backward compatible** - all new parameters are optional with
sensible defaults. No breaking changes to existing code.
## 📚 Documentation
- Updated example app with Demo 1 showcasing retry functionality with
visual feedback
- Added inline documentation for all new APIs
- Included retry button states, progress indicators, and status messages
## 🎯 Use Cases
- Apps needing explicit user control over connectivity checks
- Scenarios where automatic detection is unreliable (VPNs, proxies)
- User feedback during network troubleshooting
- Manual "refresh" functionality in offline-first apps
## 📊 Changes
- `lib/src/main.dart` - Added retry logic and state management
- `test/flutter_offline_test.dart` - Added 6 comprehensive retry tests
- `example/lib/widgets/demo_1.dart` - Enhanced demo with retry UI1 parent 30c008f commit 1046369
8 files changed
Lines changed: 707 additions & 30 deletions
File tree
- example/lib/widgets
- lib/src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
1 | 13 | | |
2 | 14 | | |
3 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
87 | 171 | | |
88 | 172 | | |
89 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | | - | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
7 | 55 | | |
8 | 56 | | |
9 | 57 | | |
| 58 | + | |
10 | 59 | | |
11 | 60 | | |
12 | 61 | | |
13 | 62 | | |
14 | 63 | | |
15 | 64 | | |
| 65 | + | |
16 | 66 | | |
17 | 67 | | |
18 | 68 | | |
19 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
20 | 135 | | |
21 | 136 | | |
22 | 137 | | |
| |||
28 | 143 | | |
29 | 144 | | |
30 | 145 | | |
31 | | - | |
| 146 | + | |
32 | 147 | | |
33 | 148 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
42 | 162 | | |
43 | | - | |
| 163 | + | |
44 | 164 | | |
45 | 165 | | |
46 | 166 | | |
| |||
49 | 169 | | |
50 | 170 | | |
51 | 171 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | 172 | | |
64 | 173 | | |
65 | 174 | | |
0 commit comments