GVKun编程网logo

flutter 学习笔记之封装一个appbar(flutter 封装组件)

15

在本文中,我们将为您详细介绍flutter学习笔记之封装一个appbar的相关知识,并且为您解答关于flutter封装组件的疑问,此外,我们还会提供一些关于AppBar中的Flutter居中文本、da

在本文中,我们将为您详细介绍flutter 学习笔记之封装一个appbar的相关知识,并且为您解答关于flutter 封装组件的疑问,此外,我们还会提供一些关于AppBar 中的 Flutter 居中文本、dart – Flutter – 改变appbar的颜色不起作用、dart – Flutter:设置AppBar的高度、flutter 1.9.1 + hotfix.2-构建appbundle失败,但实际上产生了一个appbundle的有用信息。

本文目录一览:

flutter 学习笔记之封装一个appbar(flutter 封装组件)

flutter 学习笔记之封装一个appbar(flutter 封装组件)

# Flutter_appbar

封装一个简单的appbar,默认显示title和返回按钮和下面的分割线

- PreferredSizeWidget bottom 支持自定义bottom
- titleStyle 支持自定义title的风格
- backImgName 自定义返回按钮的图片
- backgroundColor 自定义导航栏颜色
 

核心代码:

 Widget build(BuildContext context) {
    return AppBar(
      title: new Text(
        widget.title ?? 'title',
        style: new TextStyle(
          color: Colors.black,
          fontSize: 17.0,
          fontWeight: FontWeight.bold,
        ),
      ),
      leading: widget.isShowBack ?
      FlatButton(
        child: Image(
          image: new Assetimage('resources/base_navi_back@2x.png'),
          width: 9,
          height: 15,
        ),
        onpressed: () {
          Navigator.maybePop(context);
        },
      ) : null,
      backgroundColor: widget.backgroundColr ?? Colors.white,
      elevation: 0,
   
      bottom: new AppBarBottom(
        child: widget.bottom,
      ),
      actions: widget.actions,
    );
  }

源码:https://github.com/AnleSu/flutter_appbar

AppBar 中的 Flutter 居中文本

AppBar 中的 Flutter 居中文本

如何解决AppBar 中的 Flutter 居中文本?

我只想将整个文本居中(当然它应该仍在 AppBar 中)。谢谢

i want to centre entire text

4
4
f

解决方法

y 小部件中包含 mainAxisAlignmentMainAxisAlignment.center

示例代码:

Row
,

使用 centerTitle : true

appBar: AppBar(
            centerTitle: true,toolbarHeight: 80.0,backgroundColor: Colors.amber,title: Row(children: [
              Text("Text",style: GoogleFonts.josefinSans(
                      textStyle: const TextStyle(fontSize: 40.0))),Text(
                "The Game",style: GoogleFonts.overpass(
                    textStyle: const TextStyle(fontSize: 20.0)),)
            ])),

dart – Flutter – 改变appbar的颜色不起作用

dart – Flutter – 改变appbar的颜色不起作用

我试图改变AppBar的背景颜色,但它不起作用.

根据下图选择颜色0x673AB7时,AppBar变为灰色而不是紫色.

import "package:Flutter/material.dart";

void main() {
  runApp(new ControlleApp());
}

class ControlleApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: "Controlle Financeiro",home: new HomePage(),);
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        backgroundColor: new Color(0x673AB7),),);
  }
}

enter image description here

解决方法

看起来你的颜色是完全透明的.尝试将颜色更改为0xFF673AB7

dart – Flutter:设置AppBar的高度

dart – Flutter:设置AppBar的高度

如何在Flutter中设置AppBar的高度?

栏的标题应该垂直居中(在那个AppBar中).

解决方法

在撰写本文时,我不知道PreferredSize. Cinn的答案更好地实现了这一目标.

您可以使用自定义高度创建自己的自定义小部件:

import "package:Flutter/material.dart";

class Page extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Column(children : <Widget>[new CustomAppBar("Custom App Bar"),new Container()],);
  }
}


class CustomAppBar extends StatelessWidget {

  final String title;
  final double barHeight = 50.0; // change this for different heights 

  CustomAppBar(this.title);

  @override
  Widget build(BuildContext context) {
    final double statusbarHeight = MediaQuery
        .of(context)
        .padding
        .top;

    return new Container(
      padding: new EdgeInsets.only(top: statusbarHeight),height: statusbarHeight + barHeight,child: new Center(
        child: new Text(
          title,style: new TextStyle(fontSize: 20.0,fontWeight: FontWeight.bold),),);
  }
}

flutter 1.9.1 + hotfix.2-构建appbundle失败,但实际上产生了一个appbundle

flutter 1.9.1 + hotfix.2-构建appbundle失败,但实际上产生了一个appbundle

自从将flutter 1.9.1 + hotfix.2升级到我运行时flutter build appbundle,flutter以错误结束:

Initializing gradle...                                              0,9s
Resolving dependencies...                                           3,6s
Running Gradle task 'bundleRelease'...
Running Gradle task 'bundleRelease'... Done                       114,5s
Gradle build failed to produce an Android bundle package.

但实际上它确实产生了一个有效的附件,flutter build appbundle -v并以:

[   +2 ms] 161 actionable tasks: 5 executed,156 up-to-date
[ +361 ms] Running Gradle task 'bundleRelease'... (completed in 75,1s)
[   +7 ms] "flutter appbundle" took 80.137ms.
Gradle build failed to produce an Android bundle package.

#0      throwToolExit (package:flutter_tools/src/base/common.dart:28:3)
#1      _buildGradleProjectV2 (package:flutter_tools/src/android/gradle.dart:780:7)
#2      _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#3      _rootRunUnary (dart:async/zone.dart:1132:38)
#4      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#5      _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#6      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#7      Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#8      Future._completeWithValue (dart:async/future_impl.dart:522:5)
#9      _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#10     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)

似乎在完成该捆绑包后gradle崩溃了。任何人都有相同的问题或想法吗?

我的Flutter医生:位于C:\ src \ flutter的Flutter 1.9.1 +
hotfix.2版本•框架修订版2d2a1ffec9(8天前),2019-09-06 18:39:49
-0700•引擎修订版b863200c37•Dart版本2.5 .0

[√] Android工具链-为Android设备开发(Android SDK版本29.0.2)•位于C:\ Users \ dirkb \ AppData
\ Local \ Android \ sdk的Android SDK•未配置Android NDK位置(可选;可用于本机性能分析支持)
)•平台android-29,构建工具29.0.2•Java二进制文件位于:C:\ Program Files \ Android \ Android
Studio \ jre \ bin \ java•Java版本OpenJDK运行时环境(内部版本1.8.0_202-release-1483-
b03)•接受所有Android许可。

[√] Android Studio(3.5版)•C:\ Program Files \ Android \ Android Studio中的Android
Studio•Flutter插件版本39.0.3•Dart插件版本191.8423•Java版本OpenJDK运行时环境(内部版本1.8.0_202-release-1483
-b03)

今天关于flutter 学习笔记之封装一个appbarflutter 封装组件的分享就到这里,希望大家有所收获,若想了解更多关于AppBar 中的 Flutter 居中文本、dart – Flutter – 改变appbar的颜色不起作用、dart – Flutter:设置AppBar的高度、flutter 1.9.1 + hotfix.2-构建appbundle失败,但实际上产生了一个appbundle等相关知识,可以在本站进行查询。

本文标签: