小编Luk*_*der的帖子

使 SliverAppBar 将图像作为背景而不是颜色

我有一个带有背景图像的 SliverAppBar。

折叠时,它以蓝色为背景:

在此处输入图片说明 在此处输入图片说明

但是我希望它在折叠时显示背景图像而不是蓝色:

在此处输入图片说明

我怎样才能做到这一点?

我已经尝试为应用栏设置透明背景色,但没有奏效。

代码:


void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  var scrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Home());
  }
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: DefaultTabController(
          length: 2,
          child: NestedScrollView(
            headerSliverBuilder:
                (BuildContext context, bool innerBoxIsScrolled) {
              return [
                SliverAppBar(
                  expandedHeight: 200.0,
                  floating: …
Run Code Online (Sandbox Code Playgroud)

layout user-interface flutter flutter-sliver flutter-layout

11
推荐指数
1
解决办法
1万
查看次数

将投影添加到 png 图像

我想在颤动中为 png 图像(带有 alpha 的图像)添加阴影。

我已经尝试过使用 BoxShadow,但我不想有一个盒子阴影。我需要一个适应 png 图像的阴影。

想要的结果: 想要的结果

user-interface dart flutter

6
推荐指数
2
解决办法
2237
查看次数

如何将按钮添加到导航抽屉菜单?

我想在我的导航抽屉菜单中添加一个按钮,如下所示:

想要的结果

图片:想要的结果

我尝试使用 actionLayout 参数实现这一点,但我似乎只能使用右侧的一些空间,而不是整个宽度:

当前结果

图片:当前结果

标题似乎占据了左侧的空间。但我想添加一个全宽的按钮,就像第一张图片一样。

我目前的代码:

...

<item
                    android:id="@+id/nav_login"
                    android:title=""
                    app:actionLayout="@layout/button_login"
                    app:showAsAction="ifRoom"/>

...
Run Code Online (Sandbox Code Playgroud)

button_login.xml

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:background="#0000ff"
    android:text="Login"
    android:textColor="#ffffff"
    android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)

layout android menu navigation-drawer

5
推荐指数
1
解决办法
5861
查看次数

android.app.Application 无法转换为 LifecycleOwner

不幸的是,我不能使用 getApplication() 作为 LifecycleOwner,因为 android.app.Application 似乎没有实现它。

为什么 android.app.Application 没有实现 LifecycleOwner?

我尝试使用 getApplication() 作为 LiveData 的 LifecycleOwner 的代码:

result.observe(getApplication(), ....);
Run Code Online (Sandbox Code Playgroud)

摇篮:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "XXXX"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }

}

dependencies {
    // GENERAL
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation …
Run Code Online (Sandbox Code Playgroud)

android android-lifecycle androidx

5
推荐指数
1
解决办法
4296
查看次数

在BottomNavigationBar的屏幕之间水平滑动?

我想让在 BottomNavigationBar 的屏幕 (BottomNavigationBarItems) 之间水平滑动成为可能。

什么是实现这一点的好方法?

user-interface dart flutter

2
推荐指数
1
解决办法
733
查看次数