首先我们先来看下AppBar的源码,实现了PreferredSizeWidget类,我们可以知道这个类主要是控制AppBar的高度的,Scaffold脚手架里的AppBar的参数类型就是PreferredSizeWidget类型。 classAppBarextendsStatefulWidgetimplementsPreferredSizeWidget{ ... preferredSize = _PreferredAppBarSize(toolbarHeight, bottom?.preferredSize.height)...
SearchAppBar组件完整代码: import'package:flutter/material.dart';import'package:supervision/common/utils/utils.dart';classSearchAppBarextendsStatefulWidget{finalFunction(String)?onChange;finalFunction(String)?onSearch;constSearchAppBar({Key?key,this.onChange,this.onSearch}):super(key:key);@overrideState<...
;}class_SAppBarSearchStateextendsState<SAppBarSearch>{TextEditingController _controller;FocusNode _focusNode;bool isInput=false;boolgetisFocus=>_focusNode.hasFocus;boolgetisTextEmpty=>_controller.text.isEmpty;boolgetisActionEmpty=>widget.actions.isEmpty;@overridevoidinitState(){_controller=widget.controller...
appBar: AppBar(title: const Text('大前端之旅'), actions: [ // this button is used to open the search modal IconButton( icon: const Icon(Icons.search), onPressed: () => _showModal(context), ) ]), body: Container(), ); } } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12...
();}class_SearchPageStateextendsState<SearchPage>{@overrideWidgetbuild(BuildContextcontext){returnScaffold(appBar:AppBar(title:Container(child:TextField(maxLines:1,inputFormatters:[LengthLimitingTextInputFormatter(12)],autofocus:true,decoration:InputDecoration(border:OutlineInputBorder(borderRadius:BorderRadius....
~/flutter/packages/flutter/lib/src/material/search.dart // 导入icon import 'package:flutter/material.dart'; // 修改源码 直接到文件末尾 return Semantics( explicitChildNodes: true, scopesRoute: true, namesRoute: true, label: routeName, child: Theme( data: theme, child: Scaffold( appBar: AppB...
appBar: AppBar( title: Text('SearchBarDemo'), actions:<Widget>[ IconButton( icon: Icon(Icons.search), onPressed: (){ showSearch(context: context,delegate: SearchBarDelegate()); }, ) ], ), ); } } 在点击图标时执行SearchBarDelegate类,这个类继承与SearchDelegate类,继承后要重写里边的四个方法...
appBar: AppBar( title: new Text('TextField And Card Demo'), ), body: new Column( children: [ Padding( padding: EdgeInsets.only(left: 20,top: 0,right: 20,bottom: 0), child: TextField( controller: _useController,//绑定controller ...
DefaultTabController( length: 2, child: Scaffold( appBar: AppBar( centerTitle: true, title: const Text("AppBarDemoPage"), leading: IconButton( icon: const Icon(Icons.menu), onPressed: () { print(1244); }, ), actions: [ IconButton( onPressed: () {}, icon: const Icon(Icons.search...
// 关键字提示 @override Widget buildSuggestions(BuildContext context) { return Suggestions( delegate: this, query: query, ); } // 显示结果 @override Widget buildResults(BuildContext context) { return SearchResult( delegate: this, query: query, ); } // 重写主题 @override ThemeData appBarTheme...