小编Jar*_*red的帖子

ListTile 标题、尾随不居中

所以这看起来很基本,但我无法弄清楚。我有一个 ListTile,它有一个前导复选框、一个标题和一个尾随图标。在最近的 Flutter 更新中,复选框和图标由于某种原因不再居中。我希望它们垂直居中。我尝试以各种方式将 Center()、Align()、Expanded() 和 Flexible() 添加到复选框中,但它只是将标题从屏幕上推出或什么也不做。

有小费吗?任何帮助表示赞赏。

ListTile(
        leading: Checkbox(
          value: item.checked,
          onChanged: (bool newValue) {
            setState(() {
              item.checked = newValue;
            });
            firestoreUtil.updateList(user, taskList);
          },
          activeColor: Theme.of(context).primaryColor,
        ),
        title: InkWell(
            onTap: () {
              editTask(item);
            },
            child: Text(
              item.task,
              style: TextStyle(fontSize: 18),
            )),
        trailing: ReorderableListener(
          child: Container(
              padding: EdgeInsets.only(right: 16),
              child: Icon(Icons.drag_handle)),
        ),
        contentPadding: EdgeInsets.all(8),
      ),
Run Code Online (Sandbox Code Playgroud)

调试模式: ListTile 的屏幕截图

dart flutter

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

如何在 Flutter 中为列表更改设置动画

如果我有一个可以添加、删除和交换的列表(例如 ListTiles),那么动画这些更改的最佳方法是什么?如果这有所不同,我将使用可重新排序的列表。现在我的列表没有动画,我只是在数据更改时调用 setState。

dart flutter

13
推荐指数
2
解决办法
3252
查看次数

Flutter Sortable拖放ListView

因此,我开始学习Flutter,并想像在材料指南网站上看到的那样使用材料设计拖放列表。

https://storage.googleapis.com/spec-host-backup/mio-design%2Fassets%2F1dtprsH4jZ2nOnjBCJeJXd7n4U-jmWyas%2F03-list-reorder.mp4

到目前为止,我尝试过的所有库看上去都像垃圾。是否有一个我所缺少的良好库或一个Flutter原生窗口小部件?

listview drag-and-drop flutter flutter-animation

8
推荐指数
4
解决办法
6479
查看次数

Flutter Firestore 如何监听对一个文档的更改

我只想在 ONE 文档更改或更新时收到通知。每个获取更新的示例总是使用集合。我试图只使用一个文档来实现它,但它永远不会得到任何更新。这是我现在所拥有的不起作用的东西:

@override
Widget build(BuildContext context) {
StreamBuilder<DocumentSnapshot>(
    stream: Firestore.instance
        .collection("users")
        .document(widget.uid)
        .snapshots(),
    builder:
        (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
      user = snapshot.data.data as User;
    });
Run Code Online (Sandbox Code Playgroud)

我已经调试了 100 次,但它永远不会进入“builder:”部分。顺便说一下,这不是文档引用的问题。我在这里做错了什么?

dart firebase flutter google-cloud-firestore

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

Flutter Firestore - 如何读写对象数组

所以我一直在努力使用 Flutter 在 Firestore 中读写对象数组。对于写作,数组永远不会在 Firestore 中更新,我不知道为什么。我试过了:

.updateData({"tasks": FieldValue.arrayUnion(taskList.tasks)});
Run Code Online (Sandbox Code Playgroud)

.updateData(taskList.toMap());
Run Code Online (Sandbox Code Playgroud)

但似乎都没有做任何事情。

对于阅读,我通常会收到错误type 'List<dynamic>' is not a subtype of type 'List<Task>'。我很确定这与我的班级结构有关,但我无法弄清楚。我尝试了许多不同的方法来将数据作为任务列表获取,但所有尝试都失败了。这是我当前损坏的代码:

任务列表.dart

class TaskList {
  String name;
  List<Task> tasks;

  TaskList(this.name, this.tasks);

  Map<String, dynamic> toMap() => {'name': name, 'tasks': tasks};

  TaskList.fromSnapshot(DocumentSnapshot snapshot)
      : name = snapshot['name'],
        tasks = snapshot['tasks'].map((item) {
          return Task.fromMap(item);
        }).toList();

}
Run Code Online (Sandbox Code Playgroud)

任务.dart

class Task {
  String task;
  bool checked;

  Task(this.task, this.checked);

  Map<String, dynamic> toMap() => {
        'task': task,
        'checked': checked,
      };

  Task.fromMap(Map<dynamic, dynamic> map)
      : task …
Run Code Online (Sandbox Code Playgroud)

dart firebase flutter google-cloud-firestore

7
推荐指数
1
解决办法
6042
查看次数

使 Google 登录对话框不可取消

我正在将 Firebase 用于我的 Android 应用程序并实现了 Google 帐户登录。我的问题是当它显示“选择 Google 帐户”对话框时,如果您点击它,它就会关闭。有没有办法使这个对话框不可取消?

android firebase firebase-authentication google-signin

6
推荐指数
1
解决办法
1001
查看次数

第二次点击时由键盘覆盖的Android编辑文本

所以我有一个EditText,第一次没有被键盘覆盖.然后当您关闭键盘并再次点击edittext时,它将覆盖edittext.

我花了几个小时研究这个问题并得出结论它与编辑文本的这两个属性有关.

android:inputType="number"
android:gravity="center"
Run Code Online (Sandbox Code Playgroud)

如果我删除其中任何一个,adjustPan(如我的清单中所示)始终按照承诺运行.似乎是一个Android错误.但是我在编辑文本中需要这两行.解决这个问题的最佳方法是什么?

这是一个略微浓缩的xml版本:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true">


<LinearLayout
    android:id="@+id/buttons_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal"
    android:weightSum="5">

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/generate_button"
        android:layout_width="match_parent"
        android:layout_height="@dimen/button_height"
        android:layout_marginBottom="@dimen/button_margin"
        android:layout_marginEnd="0dp"
        android:layout_marginLeft="@dimen/button_margin"
        android:layout_marginRight="0dp"
        android:layout_marginStart="@dimen/button_margin"
        android:layout_marginTop="@dimen/button_margin"
        android:layout_weight="1"
        android:background="@color/buttonColor"
        android:elevation="@dimen/button_elevation"
        android:foreground="?attr/selectableItemBackground"
        android:text="@string/generate"
        android:textColor="@color/colorPrimary"
        android:textSize="@dimen/generate_button_title_size"
        android:textStyle="bold" />

    <android.support.v7.widget.AppCompatImageButton
        android:id="@+id/copy_button"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/button_margin"
        android:layout_weight="4"
        android:adjustViewBounds="true"
        android:background="@color/buttonColor"
        android:elevation="@dimen/button_elevation"
        android:foreground="?attr/selectableItemBackground"
        android:padding="@dimen/button_margin"
        android:scaleType="fitCenter"
        android:src="@drawable/ic_copy"
        android:tint="@color/colorPrimary" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/buttons_layout"
    android:orientation="vertical"
    android:weightSum="10">

    <GridLayout
        android:id="@+id/grid_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_weight="6"
        android:animateLayoutChanges="true">
    </GridLayout>


    <TextView
        android:id="@+id/total_text_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:gravity="center"
        android:text="11"
        android:textSize="@dimen/toolbar_title_size"
        android:textStyle="bold" /> …
Run Code Online (Sandbox Code Playgroud)

java keyboard android android-edittext

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

Flutter 动态主题

动态更改 Flutter 应用程序主题的最佳方法是什么?例如,如果用户将颜色更改为红色,我希望主题立即更改为红色。除了一个人说要使用我不熟悉的 BLOC 模式之外,我在网上找不到任何非常有用的东西。我想听听你们对这个问题的看法。谢谢!

我目前的代码结构:

var themeData = ThemeData(
    fontFamily: 'Raleway',
    primaryColor: Colors.blue,
    brightness: Brightness.light,
    backgroundColor: Colors.white,
    accentColor: Colors.blue);

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: Constants.appName,
      theme: themeData,
      home: CheckAuth(), //CheckAuth returns MyHomePage usually
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title, @required this.uid}) : super(key: key);

  final String title;
  final String uid;

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

class …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

从内部侦听器中删除 Firestore 快照侦听器

超级简单的问题。一旦我到达我的听众内部的某个点,我需要删除一个 firestore 快照听众。看起来这应该非常简单,但我无法弄清楚。谢谢!

示例代码:

val registration = gameRef.addSnapshotListener { snapshot, e ->
     //code....

     //if(condition is meet){
     //    destroy this listener
     //}
}
Run Code Online (Sandbox Code Playgroud)

android firebase google-cloud-firestore

4
推荐指数
1
解决办法
848
查看次数

Android Material Drawer删除帐户标题dropdwon

如何使用Mike Penz使用Material Drawer库删除显示AccountHeader的已连接帐户的下拉菜单?

我目前的代码:

// Create the AccountHeader
            AccountHeader headerResult = new AccountHeaderBuilder()
                    .withActivity(this)
                    //.withHeaderBackground(R.drawable.header)
                    .addProfiles(
                            new ProfileDrawerItem().withName(displayName).withEmail(email).withIcon(firebaseUser.getPhotoUrl())
                    )
                    .withCompactStyle(true)
                    .withTextColor(getResources().getColor(R.color.itemTextColor))
                    .build();
Run Code Online (Sandbox Code Playgroud)

account android header drawer

3
推荐指数
1
解决办法
515
查看次数

浮动操作按钮不在右下角

由于某种原因,我的 FAB 不会像往常一样进入屏幕的右下角。我在一个片段中,该片段是一个协调器布局(我不知道这是否是一个好习惯)。

这是布局xml代码:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.gigstudios.polls.fragment.MyPollsFragment">

    <LinearLayout
        android:id="@+id/linear_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </android.support.v7.widget.RecyclerView>

    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_add_white_36dp"
        app:fabSize="normal"
        app:layout_anchor="@id/linear_layout"
        app:layout_anchorGravity="bottom|right|end" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

出于某种原因,FAB 最终位于右上角而不是右下角。有谁知道我做错了什么?

顺便说一句,xml 预览总是在右下角显示 fab 按钮,但是当我在手机上运行它时,它在右上角。

编辑:这是我的 main_activity xml,用于显示我放置片段的位置(“容器”FrameLayout)。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorGrey">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorGrey"
        android:layout_marginTop="?attr/actionBarSize">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/container">
        </FrameLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android gravity floating-action-button android-coordinatorlayout

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

Android Firebase查询StartAt()

我在我的Android应用程序中使用查询并遇到一些麻烦.我的数据库最终会有数百或数千个轮询对象.我想一次大约20个,一旦我完成了20个,我会得到下一个20个.我可以很容易地得到前20个但是当我尝试使用startAt()查询时却没有得到任何东西.

这是我的代码:

pollQuery = rootRef.child(getString(R.string.poll_ref)).startAt(lastPollFromQuery).orderByChild(getString(R.string.timestamp_ref)).limitToFirst(numPollsToLoad);
Run Code Online (Sandbox Code Playgroud)

我已经尝试使用Integer positionfor lastPollFromQuery和我当前正在使用String(轮询对象的键).我也围着这个进行了洗牌startAt(),orderByChild()但这并没有做太多.

我究竟做错了什么?

android firebase firebase-realtime-database

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

Android Firebase 数据库加载速度更快

我正在使用适用于 Android 的 Firebase 数据库,但遇到了一些速度问题。检索许多自定义对象时需要很长时间(例如每个对象需要 1/2 - 1 秒)。我正在加载一堆存储在 FB 中的 Poll 对象。

这是我目前如何为每个民意调查做的一个例子:

pollRef = rootRef.child(getString(R.string.poll_ref)).child(myPollIds.get(polls.size()));

        pollRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (isAdded()) {
                    Poll poll = dataSnapshot.getValue(Poll.class);
Run Code Online (Sandbox Code Playgroud)

我现在正在尝试加载单独下载我需要使用的投票的特定部分。它变得相当复杂。有没有更好的方法来有效地只从数据库中获取部分对象?

例如,我只想要对象的突出显示部分。 在此处输入图片说明

提前致谢!:)

performance android loading firebase firebase-realtime-database

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