[英]How can i make full menu come out while mouse hover in the AppBar in flutter?
[英]How come I can't make a Material AppBar a separate class?
我正在嘗試將我的Scaffold
小部件中的應用欄代碼分離到一個單獨的 class 中。
我寫了這個(編譯但沒有正確顯示):
class MyAppBar extends AppBar {
Widget build(BuildContext context) {
return AppBar(
title: const Text('Sample Code'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.menu),
tooltip: 'Navigation menu',
onPressed: null,
),
IconButton(
icon: Icon(Icons.search),
tooltip: 'Search',
onPressed: null,
),
],
);
}
}
class MyScaffold extends StatefulWidget {
_MyScaffoldState createState() => _MyScaffoldState();
}
class _MyScaffoldState extends State<MyScaffold> {
bool pressed = false;
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(),
當此代碼編譯並正確顯示 AppBar 時:
class MyScaffold extends StatefulWidget {
_MyScaffoldState createState() => _MyScaffoldState();
}
class _MyScaffoldState extends State<MyScaffold> {
bool pressed = false;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Sample Code'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.menu),
tooltip: 'Navigation menu',
onPressed: null,
),
IconButton(
icon: Icon(Icons.search),
tooltip: 'Search',
onPressed: null,
),
],
),
任何人都可以幫我解決發生的事情嗎?
在這里回答: 單獨處理應用欄
我需要class MyAppBar extends StatelessWidget
為class MyAppBar extends StatelessWidget implements PreferredSizeWidget
我正在嘗試將我的Scaffold
小部件中的應用欄代碼分離為單獨的 class。
我寫了這個(編譯但沒有正確顯示):
class MyAppBar extends AppBar {
Widget build(BuildContext context) {
return AppBar(
title: const Text('Sample Code'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.menu),
tooltip: 'Navigation menu',
onPressed: null,
),
IconButton(
icon: Icon(Icons.search),
tooltip: 'Search',
onPressed: null,
),
],
);
}
}
class MyScaffold extends StatefulWidget {
_MyScaffoldState createState() => _MyScaffoldState();
}
class _MyScaffoldState extends State<MyScaffold> {
bool pressed = false;
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(),
雖然此代碼編譯並正確顯示 AppBar:
class MyScaffold extends StatefulWidget {
_MyScaffoldState createState() => _MyScaffoldState();
}
class _MyScaffoldState extends State<MyScaffold> {
bool pressed = false;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Sample Code'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.menu),
tooltip: 'Navigation menu',
onPressed: null,
),
IconButton(
icon: Icon(Icons.search),
tooltip: 'Search',
onPressed: null,
),
],
),
任何人都可以幫我解決發生了什么嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.