gpt4 book ai didi

flutter - 如何创建自定义 AppBar 小部件?

转载 作者:IT王子 更新时间:2023-10-29 06:35:33 26 4
gpt4 key购买 nike

我是 Flutter 的新手。我正在尝试创建一个自定义应用栏小部件并在页面中导入该小部件。

但我无法创建小部件。

import 'package:flutter/material.dart';

class AppBar extends StatelessWidget{
@override
Widget build(BuildContext context){
return AppBar(
title: Text('Ordering'),
actions: <Widget>[
IconButton(
onPressed: _incrementCounter,
icon: Icon(Icons.add),
),
BadgeIconButton(
itemCount: _counter,
badgeColor: Color.fromRGBO(37, 134, 16, 1.0),
badgeTextColor: Colors.white,
icon: Icon(Icons.shopping_cart, size: 30.0,),
onPressed: () {}
),
],
);

}}'

最佳答案

import 'package:flutter/material.dart';

class CustomAppBar extends StatefulWidget implements PreferredSizeWidget {
CustomAppBar({Key key}) : preferredSize = Size.fromHeight(kToolbarHeight), super(key: key);

@override
final Size preferredSize; // default is 56.0

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

class _CustomAppBarState extends State<CustomAppBar>{

@override
Widget build(BuildContext context) {
return AppBar( title: Text("Sample App Bar") );
}
}

希望对你有帮助

关于flutter - 如何创建自定义 AppBar 小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53294006/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com