an_console 0.1.0 an_console: ^0.1.0 copied to clipboard
A developer can fully customize the console content, which can be used to display logs on the UI, serve as an app configuration center, and more functionalities.
import 'package:an_console/an_console.dart';
import 'package:flutter/material.dart';
import 'debug/debug_config.dart';
import 'debug/debug_demo.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
//必须在WidgetsFlutterBinding.ensureInitialized 之后使用
AnConsole.instance.addConsole('Conf', DebugConfig());
AnConsole.instance.addConsole('DebugDemo', DebugDemo());
runApp(const MyApp());
//放在runApp之后也可以
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'AnConsole Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'AnConsole Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}