Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Whatsapp式搜索图标,点击时覆盖标题,但在正文中-使用颤振_Flutter_Dart_Material Design - Fatal编程技术网

Flutter Whatsapp式搜索图标,点击时覆盖标题,但在正文中-使用颤振

Flutter Whatsapp式搜索图标,点击时覆盖标题,但在正文中-使用颤振,flutter,dart,material-design,Flutter,Dart,Material Design,我如何创建一个类似于Whatsapp在appBar中但在body中使用的搜索 左边是标题,右边是放大镜图标。当您单击图标时,将在标题顶部打开搜索输入。更新的答案 导入“包装:颤振/材料.省道”; 导入“package:flatter/widgets.dart”; void main(){ runApp(MyApp()); } 类MyApp扩展了无状态小部件{ @凌驾 小部件构建(构建上下文){ 返回材料PP( 标题:“颤振演示”, debugShowCheckedModeBanner:fal

我如何创建一个类似于Whatsapp在appBar中但在body中使用的搜索


左边是标题,右边是放大镜图标。当您单击图标时,将在标题顶部打开搜索输入。

更新的答案

导入“包装:颤振/材料.省道”;
导入“package:flatter/widgets.dart”;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
debugShowCheckedModeBanner:false,
主题:主题数据(
主样本:颜色。蓝色,
视觉密度:视觉密度。自适应平台密度,
),
主页:MyHomePage(),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key}):超级(Key:Key);
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
bool\u showSearch=false;
FocusNode _FocusNode;
Widget_searchBar(){
返回容器(
填充:常量边集。对称(水平:10),
child:\u showSearch
?行(
儿童:[
图标按钮(
图标:图标(图标。箭头返回),
已按下:(){
设置状态(){
_showSearch=false;
(上下文)的焦点范围。取消焦点();
});
},
),
扩大(
孩子:TextField(
focusNode:_focusNode,
自动对焦:对,
样式:TextStyle(
颜色:颜色,白色,
),
装饰:输入装饰(
hintText:“Filtro”,
hintStyle:TextStyle(
颜色:颜色,白色,
),
边框:InputBorder.none,
FocusedOrder:InputBorder.none,
enabledBorder:InputBorder.none,
errorBorder:InputBorder.none,
disabledBorder:InputBorder.none,
),
),
),
],
)
:行(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
正文(
“WhatsApp”,
),
图标按钮(
图标:图标(
Icons.search,
),
已按下:(){
设置状态(){
_showSearch=true;
FocusScope.of(上下文).requestFocus(_focusNode);
});
},
),
],
),
);
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“搜索”),
),
主体:容器(
颜色:颜色。灰色[300],
填充:常量边集。全部(10),
子:列(
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
容器(
身高:100,
颜色:颜色,白色,
子:列(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
容器(
身高:50,
对齐:对齐.center,
子:文本(
“此处的选项卡视图”,
),
),
_搜索栏(),
],
),
),
扩大(
子:ListView(
填充:常量边集。全部(5),
儿童:[
列表砖(
标题:文本(“磁贴1”),
字幕:文本(“内容”),
),
列表砖(
标题:文本(“瓷砖2”),
字幕:文本(“内容”),
),
],
),
),
],
),
),
);
}
}
旧答案

你是说像这样吗

导入“包装:颤振/材料.省道”;
导入“package:flatter/widgets.dart”;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
debugShowCheckedModeBanner:false,
主题:主题数据(
主样本:颜色。蓝色,
视觉密度:视觉密度。自适应平台密度,
),
主页:MyHomePage(),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key}):超级(Key:Key);
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
bool\u showSearch=false;
FocusNode _FocusNode;
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
前导:\u showSearch
?图标按钮(
图标:图标(图标。箭头返回),
已按下:(){
设置状态(){
_showSearch=false;
(上下文)的焦点范围。取消焦点();
});
},
)
:null,
标题:_showSearch
?文本字段(
focusNode:_focusNode,
自动对焦:对,
样式:TextStyle(
颜色:颜色,白色,
),
装饰:输入装饰(
hintText:“搜索…”,
hintStyle:TextStyle(
颜色:颜色,白色,
),
博尔
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

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

class _MyHomePageState extends State<MyHomePage> {
  bool _showSearch = false;
  FocusNode _focusNode;

  Widget _searchBar() {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 10),
      child: _showSearch
          ? Row(
              children: [
                IconButton(
                  icon: Icon(Icons.arrow_back),
                  onPressed: () {
                    setState(() {
                      _showSearch = false;
                      FocusScope.of(context).unfocus();
                    });
                  },
                ),
                Expanded(
                  child: TextField(
                    focusNode: _focusNode,
                    autofocus: true,
                    style: TextStyle(
                      color: Colors.white,
                    ),
                    decoration: InputDecoration(
                      hintText: 'Filtro',
                      hintStyle: TextStyle(
                        color: Colors.white,
                      ),
                      border: InputBorder.none,
                      focusedBorder: InputBorder.none,
                      enabledBorder: InputBorder.none,
                      errorBorder: InputBorder.none,
                      disabledBorder: InputBorder.none,
                    ),
                  ),
                ),
              ],
            )
          : Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  'WhatsApp',
                ),
                IconButton(
                  icon: Icon(
                    Icons.search,
                  ),
                  onPressed: () {
                    setState(() {
                      _showSearch = true;
                      FocusScope.of(context).requestFocus(_focusNode);
                    });
                  },
                ),
              ],
            ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Search'),
      ),
      body: Container(
        color: Colors.grey[300],
        padding: const EdgeInsets.all(10),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Container(
              height: 100,
              color: Colors.white,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    height: 50,
                    alignment: Alignment.center,
                    child: Text(
                      'Tab view here',
                    ),
                  ),
                  _searchBar(),
                ],
              ),
            ),
            Expanded(
              child: ListView(
                padding: const EdgeInsets.all(5),
                children: [
                  ListTile(
                    title: Text('Tile 1'),
                    subtitle: Text('Content'),
                  ),
                  ListTile(
                    title: Text('Tile 2'),
                    subtitle: Text('Content'),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

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

class _MyHomePageState extends State<MyHomePage> {
  bool _showSearch = false;
  FocusNode _focusNode;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: _showSearch
            ? IconButton(
                icon: Icon(Icons.arrow_back),
                onPressed: () {
                  setState(() {
                    _showSearch = false;
                    FocusScope.of(context).unfocus();
                  });
                },
              )
            : null,
        title: _showSearch
            ? TextField(
                focusNode: _focusNode,
                autofocus: true,
                style: TextStyle(
                  color: Colors.white,
                ),
                decoration: InputDecoration(
                  hintText: 'Search...',
                  hintStyle: TextStyle(
                    color: Colors.white,
                  ),
                  border: InputBorder.none,
                  focusedBorder: InputBorder.none,
                  enabledBorder: InputBorder.none,
                  errorBorder: InputBorder.none,
                  disabledBorder: InputBorder.none,
                ),
              )
            : Text('WhatsApp'),
        actions: _showSearch
            ? []
            : [
                IconButton(
                  icon: Icon(
                    Icons.search,
                    color: Colors.white,
                  ),
                  onPressed: () {
                    setState(() {
                      _showSearch = true;
                      FocusScope.of(context).requestFocus(_focusNode);
                    });
                  },
                ),
                IconButton(
                  icon: Icon(
                    Icons.more_vert,
                    color: Colors.white,
                  ),
                ),
              ],
      ),
      body: Center(
        child: Text('Content'),
      ),
    );
  }
}