import 'package:flutter/material.dart';

class AutoInjectPage extends StatefulWidget { const AutoInjectPage({Key? key}) : super(key: key);

@override _AutoInjectPageState createState() => _AutoInjectPageState(); }

class _AutoInjectPageState extends State { int _selectedIndex = -1; List<Map<String, String>> _stringList = [ {'act': 'click', 'prompt': '点击按钮'}, {'act': 'input', 'prompt': '输入文本'}, {'act': 'wait', 'prompt': '等待页面加载'}, {'act': 'scroll', 'prompt': '滚动页面'}, {'act': 'assert', 'prompt': '断言页面元素'}, ]; List<Map<String, String>> _filteredStringList = [];

@override void initState() { super.initState(); _filteredStringList = List.from(_stringList); }

void _onSearch(String keyword) { setState(() { _filteredStringList = _stringList.where((item) { return item['act']!.contains(keyword) || item['prompt']!.contains(keyword); }).toList(); }); }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('自动注入'), actions: [ IconButton( icon: const Icon(Icons.search), onPressed: () { showSearch(context: context, delegate: _SearchBarDelegate(onSearch: _onSearch)); }, ), ], ), body: ListView.builder( itemCount: _filteredStringList.length, itemBuilder: (BuildContext context, int index) { String act = _filteredStringList[index]['act']!; String prompt = _filteredStringList[index]['prompt']!; return RadioListTile( title: Text('行为: $act'), subtitle: Text('语句: $prompt'), value: index, groupValue: _selectedIndex, onChanged: (int? value) { setState(() { _selectedIndex = value!; }); }, ); }, ), ); } }

class _SearchBarDelegate extends SearchDelegate { final Function(String) onSearch;

_SearchBarDelegate({required this.onSearch});

@override List buildActions(BuildContext context) { return [ IconButton( icon: const Icon(Icons.clear), onPressed: () { query = ''; }, ), ]; }

@override Widget buildLeading(BuildContext context) { return IconButton( icon: const Icon(Icons.arrow_back), onPressed: () { close(context, ''); }, ); }

@override Widget buildResults(BuildContext context) { onSearch(query); return const SizedBox.shrink(); }

@override Widget buildSuggestions(BuildContext context) { return const SizedBox.shrink(); } }

Flutter 自动注入功能:快速添加行为和语句

原文地址: https://www.cveoy.top/t/topic/lQrQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录