nian_toolkit 0.0.8
nian_toolkit: ^0.0.8 copied to clipboard
In-app debugging toolkit with floating ball, inspectors, and utilities.
import 'dart:developer';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:nian_toolkit/toolkit.dart';
import 'custom_plug/custom_pluggable.dart';
// import './custom_plug/custom_pluggable.dart';
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
void main() {
// 设置透明状态栏
if (Platform.isAndroid) {
SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
ToolKit.run(
const MyApp(),
pluginsList: [CustomPluggable()],
autoCollectLogs: false,
);
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
// This widget is the root of your application.
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this); // 注册监听器
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: const MyHomePage(title: 'Flutter Demo Home Page'),
navigatorKey: navigatorKey,
navigatorObservers: [RouteHistoryObserver()],
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
int _counter = 0;
void _incrementCounter() async {
setState(() {
_counter++;
});
log(_counter.toString());
log(list[2]);
}
@override
void initState() {
super.initState();
}
List<String> list = ['苹果', '香蕉'];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// Text(list[2]),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
ElevatedButton(
onPressed: () => ToolKit.show(isDarkMode: true),
child: const Text('显示 暗黑'),
),
ElevatedButton(
onPressed: () => ToolKit.show(isDarkMode: false),
child: const Text('显示'),
),
ElevatedButton(
onPressed: () => ToolKit.hide(),
child: const Text('隐藏'),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}