|
| 1 | +/* |
| 2 | + * This file is part of wger Workout Manager <https://github.com/wger-project>. |
| 3 | + * Copyright (c) 2026 wger Team |
| 4 | + * |
| 5 | + * wger Workout Manager is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Affero General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Affero General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Affero General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +import 'package:flutter/widgets.dart'; |
| 20 | + |
| 21 | +/// Runs [action] on the next frame: UI side effects (dialogs, snackbars, |
| 22 | +/// navigation) are illegal during build, but error handlers and provider |
| 23 | +/// listeners can fire there. Schedules a frame so idle-time requests run too. |
| 24 | +void runAfterFrame(VoidCallback action) { |
| 25 | + WidgetsBinding.instance.addPostFrameCallback((_) => action()); |
| 26 | + WidgetsBinding.instance.scheduleFrame(); |
| 27 | +} |
| 28 | + |
| 29 | +/// Yields past the synchronous phase of a provider create or widget |
| 30 | +/// life-cycle callback: reading a dirty provider there flushes it mid-build |
| 31 | +/// and crashes. A microtask, not a timer, since widget tests assert |
| 32 | +/// !timersPending at teardown. |
| 33 | +Future<void> yieldPastBuild() => Future<void>.microtask(() {}); |
0 commit comments