final controller = DebugConsole.instance;
const projectApiToken = String.fromEnvironment('GEM_TOKEN');
void main() async {
Debug.logCallObjectMethod = true;
Debug.logCreateObject = true;
Debug.logLevel = GemLoggingLevel.all;
Debug.logListenerMethod = true;
DebugConsole.listen(() {
runApp(const MyApp());
});
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Send Debug Info',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void dispose() {
GemKit.release();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.deepPurple[900],
title: const Text(
'Send Debug Info',
style: TextStyle(color: Colors.white),
),
actions: [
IconButton(
onPressed: _shareLogs,
icon: const Icon(Icons.share, color: Colors.white),
),
],
),
body: const GemMap(
key: ValueKey("GemMap"),
appAuthorization: projectApiToken,
),
);
}
Future<void> _shareLogs() async {
try {
final logs = DebugConsole.instance.logs;
if (logs.isEmpty) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('No logs to share')));
return;
}
final processedLogs = List<DebugConsoleLog>.from(logs)
..sort((a, b) => a.timestamp.compareTo(b.timestamp));
final directory = await getTemporaryDirectory();
final file = File('${directory.path}/debug_logs.txt');
await file.writeAsString(
processedLogs.map((log) => log.toString()).join('\n'),
);
await Share.shareXFiles([XFile(file.path)], text: 'Debug Logs');
} catch (e) {
print('Error sharing logs: $e');
}
}
}