fix: resolve startup crash and CrashScreen button crashes (#127)
Two bugs caused the crash-at-startup report: 1. CrashScreen used the widget's build context (above its own MaterialApp) for ScaffoldMessenger.of() in button callbacks. When the screen is the root widget — the runApp() path after a startup crash — there is no ScaffoldMessenger above it, so both 'Copy to Clipboard' and 'Report Issue on Codeberg' crashed with a null check error. Fix: wrap Scaffold.body in Builder to obtain a context that is a descendant of the Scaffold. 2. path_provider_android 2.2.21 updated to Pigeon 26, which causes a channel-error on startup for some Android devices. Pin to <2.2.21 (resolves to 2.2.20, which uses the stable pre-Pigeon-26 implementation). Additionally, make initDatabasePath() catch PlatformException so a channel error at the very start of main() no longer hard-crashes the app; _openConnection()'s lazy fallback retries after runApp() completes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
c4e7042430
commit
23cbe4611c
@@ -3,6 +3,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
@@ -578,9 +579,16 @@ String? _dbPath;
|
||||
|
||||
/// Call after WidgetsFlutterBinding.ensureInitialized() so that the
|
||||
/// path_provider plugin channel is registered before the first DB access.
|
||||
/// On some Android versions the Pigeon channel is not ready at the very
|
||||
/// start of main(); if it fails, _openConnection() retries lazily.
|
||||
Future<void> initDatabasePath() async {
|
||||
final dir = await getApplicationSupportDirectory();
|
||||
_dbPath = p.join(dir.path, 'sharedinbox.db');
|
||||
try {
|
||||
final dir = await getApplicationSupportDirectory();
|
||||
_dbPath = p.join(dir.path, 'sharedinbox.db');
|
||||
} on PlatformException {
|
||||
// Channel not yet established; LazyDatabase will resolve the path
|
||||
// on first access, after runApp() completes initialization.
|
||||
}
|
||||
}
|
||||
|
||||
LazyDatabase _openConnection() {
|
||||
|
||||
Reference in New Issue
Block a user