-
Notifications
You must be signed in to change notification settings - Fork 29k
Closed
Description
Problem
The TextFormField
on AppBar is a little higher than the back button on AppBar, and having space on left and right. As the following screenshot shows.
I want to align vertical center and removing the left and right space, to simulate a search bar.
Code
class TumblrSearchInputScreen extends StatefulWidget {
final String initialTag;
final void Function(String) search;
TumblrSearchInputScreen({
Key key,
this.initialTag,
@required this.search,
}) : super(key: key);
@override
_TumblrSearchInputScreenState createState() =>
_TumblrSearchInputScreenState();
}
class _TumblrSearchInputScreenState extends State<TumblrSearchInputScreen> {
static final _bodyKey = GlobalKey<_BodyState>();
final _formKey = GlobalKey<FormState>();
TextEditingController _textController;
String tag = '';
@override
void initState() {
super.initState();
_textController = TextEditingController(text: widget.initialTag);
}
void _submit() {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
widget.search(tag);
Navigator.of(context).pop();
}
}
String _validateTag(String tag) {
if (tag.isEmpty) {
return '请输入关键字';
}
return '';
}
@override
Widget build(BuildContext context) {
return StoreConnector<AppState, _ViewModel>(
converter: (store) => _ViewModel(
tags: store.state.tumblr.tags,
),
builder: (context, vm) => Scaffold(
appBar: AppBar(
// automaticallyImplyLeading: false,
title: Form(
key: _formKey,
child: TextFormField(
decoration: InputDecoration(
border: InputBorder.none,
// prefixIcon: IconButton(
// onPressed: () => Navigator.of(context).pop(),
// icon: Icon(Icons.arrow_back, color: TblTheme.whiteLight),
// ),
hintText: '请输入关键字',
hintStyle: TextStyle(color: TblTheme.whiteNormal),
suffixIcon: GestureDetector(
onTap: Feedback.wrapForTap(
_textController.clear,
context,
),
child: Icon(Icons.clear, color: TblTheme.whiteLight),
),
),
validator: _validateTag,
onSaved: (value) => tag = value.trim(),
onFieldSubmitted: (value) => _submit(),
autofocus: true,
maxLength: 20,
controller: _textController,
style: TextStyle(
color: TblTheme.whiteNormal,
fontSize: TblTheme.fontSizeLarge,
),
),
),
),
body: _Body(
key: _bodyKey,
vm: vm,
search: widget.search,
),
),
);
}
}
MickaelHrndz
Metadata
Metadata
Assignees
Labels
No labels