import 'package:flutter/material.dart'; import 'package:yx_net_inspector/yx_net_inspector.dart'; import 'pages/demo_page.dart'; import 'pages/dio_demo_page.dart'; import 'pages/settings_page.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'YX 网络检查器演示', theme: ThemeData( primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, appBarTheme: const AppBarTheme( backgroundColor: Colors.blue, foregroundColor: Colors.white, elevation: 2, ), elevatedButtonTheme: ElevatedButtonThemeData( style: ElevatedButton.styleFrom( backgroundColor: Colors.blue, foregroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8), ), ), ), ), home: YxNetInspector( config: const YxNetInspectorConfig( showFloatingBall: true, ballSize: 70.0, ballColor: Colors.blue, showInDebugMode: true, showInReleaseMode: false, maxLogs: 1000, draggable: true, showBadge: true, autoHide: false, ), theme: const YxNetInspectorTheme( primaryColor: Colors.blue, backgroundColor: Colors.white, textColor: Colors.black87, successColor: Colors.green, errorColor: Colors.red, warningColor: Colors.orange, cardColor: Colors.white, ), child: const MainPage(), ), debugShowCheckedModeBanner: false, ); } } class MainPage extends StatefulWidget { const MainPage({super.key}); @override State createState() => _MainPageState(); } class _MainPageState extends State { int _selectedIndex = 0; final List _pages = [ const DemoPage(), const DioDemoPage(), const SettingsPage(), ]; final List _titles = [ '功能演示', 'Dio 集成', '设置选项', ]; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('YX 网络检查器 - ${_titles[_selectedIndex]}'), actions: [ IconButton( icon: const Icon(Icons.info_outline), onPressed: _showInfoDialog, tooltip: '关于', ), IconButton( icon: const Icon(Icons.clear_all), onPressed: _clearAllLogs, tooltip: '清空所有日志', ), ], ), body: _pages[_selectedIndex], bottomNavigationBar: BottomNavigationBar( currentIndex: _selectedIndex, onTap: (index) { setState(() { _selectedIndex = index; }); }, items: const [ BottomNavigationBarItem( icon: Icon(Icons.play_circle_outline), label: '功能演示', ), BottomNavigationBarItem( icon: Icon(Icons.http), label: 'Dio 集成', ), BottomNavigationBarItem( icon: Icon(Icons.settings), label: '设置', ), ], ), ); } void _clearAllLogs() { YxNetInspectorController.instance.clearLogs(); ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('所有日志已清空'), duration: Duration(seconds: 2), ), ); } void _showInfoDialog() { showDialog( context: context, builder: (context) => AlertDialog( title: const Text('关于 YX 网络检查器'), content: const SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text( '🕵️‍♂️ YX Net Inspector', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), SizedBox(height: 8), Text('一个功能强大的Flutter网络调试工具'), SizedBox(height: 16), Text( '主要功能:', style: TextStyle(fontWeight: FontWeight.bold), ), SizedBox(height: 4), Text('• 🎯 悬浮调试球 - 实时显示网络状态'), Text('• 📊 详细日志记录 - 完整的请求/响应信息'), Text('• 🔍 智能搜索过滤 - 快速定位问题'), Text('• 🎨 主题定制 - 个性化界面'), Text('• 🚀 零依赖 - 纯Flutter实现'), SizedBox(height: 16), Text( '使用提示:', style: TextStyle(fontWeight: FontWeight.bold), ), SizedBox(height: 4), Text('1. 点击屏幕上的蓝色悬浮球打开检查器'), Text('2. 在功能演示页面测试各种网络请求'), Text('3. 在Dio集成页面查看真实HTTP请求'), Text('4. 在设置页面自定义检查器配置'), ], ), ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: const Text('知道了'), ), ], ), ); } }