|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_focus_debugger/flutter_focus_debugger.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + runApp(const ExampleApp()); |
| 6 | +} |
| 7 | + |
| 8 | +class ExampleApp extends StatelessWidget { |
| 9 | + const ExampleApp({super.key}); |
| 10 | + |
| 11 | + @override |
| 12 | + Widget build(BuildContext context) { |
| 13 | + return FocusDebugger( |
| 14 | + child: MaterialApp( |
| 15 | + home: _ExampleScreen(), |
| 16 | + theme: ThemeData(brightness: Brightness.dark), |
| 17 | + debugShowCheckedModeBanner: false, |
| 18 | + ), |
| 19 | + ); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +class _ExampleScreen extends StatefulWidget { |
| 24 | + const _ExampleScreen(); |
| 25 | + |
| 26 | + @override |
| 27 | + State<_ExampleScreen> createState() => _ExampleScreenState(); |
| 28 | +} |
| 29 | + |
| 30 | +class _ExampleScreenState extends State<_ExampleScreen> { |
| 31 | + final _backButtonFocusNode = FocusNode(debugLabel: "Back Button"); |
| 32 | + final _textFieldFocusNode = FocusNode(debugLabel: "Text Field"); |
| 33 | + final _buttonFocusNode = FocusNode(debugLabel: "Button"); |
| 34 | + |
| 35 | + @override |
| 36 | + Widget build(BuildContext context) { |
| 37 | + return Scaffold( |
| 38 | + appBar: AppBar( |
| 39 | + leading: IconButton( |
| 40 | + focusNode: _backButtonFocusNode, |
| 41 | + onPressed: () {}, |
| 42 | + icon: Icon(Icons.arrow_back_ios), |
| 43 | + ), |
| 44 | + title: Text("Flutter Focus Debugger"), |
| 45 | + ), |
| 46 | + body: Center( |
| 47 | + child: Padding( |
| 48 | + padding: const EdgeInsets.all(48), |
| 49 | + child: Column( |
| 50 | + mainAxisSize: MainAxisSize.min, |
| 51 | + spacing: 24, |
| 52 | + children: [ |
| 53 | + TextField( |
| 54 | + focusNode: _textFieldFocusNode, |
| 55 | + ), |
| 56 | + ElevatedButton( |
| 57 | + focusNode: _buttonFocusNode, |
| 58 | + onPressed: () {}, |
| 59 | + child: Text("Click Me!"), |
| 60 | + ), |
| 61 | + ], |
| 62 | + ), |
| 63 | + ), |
| 64 | + ), |
| 65 | + ); |
| 66 | + } |
| 67 | +} |
0 commit comments