小编Har*_*jem的帖子

为什么没有定义 ChangeNotifierProvider 类?

我正在尝试使用Flutter Provider 包中ChangeNotifierProvider类。但是,它给了我一个错误说

未为类 MyCustomWidget 定义该方法

我已将提供程序依赖项添加到我的pubspec.yaml文件中。

我有一个像这样的自定义小部件类

@override
Widget build(BuildContext context) {
    return ChangeNotifierProvider<Name>()
}
Run Code Online (Sandbox Code Playgroud)

yaml flutter

14
推荐指数
2
解决办法
3884
查看次数

在 Flutter 应用程序中的 ListView 滚动上隐藏/关闭键盘

我在 Flutter 应用中有聊天窗口。消息显示为小部件内的ListView小部件,我还有附加到窗口底部的消息输入小部件。

我想要

  1. 当我滚动时隐藏键盘 ListView
  2. 添加新消息时滚动到最后一条消息 InputWidget

代码:

class _MessagesPageState extends State<MessagesPage> {
  final ScrollController listScrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
    ....
    body: Stack(
        children: [
          ListView.builder(
              controller: listScrollController
              ....
          ),
          InputWidget()]
    );
}

class InputWidget extends StatelessWidget {

  final TextEditingController _textEditingController = TextEditingController();

....
Row (
  children: [
    TextField(
     controller: _textEditingController
    ), 
    IconButton(icon: ...., onPressed: (){})
  ]
 )}
Run Code Online (Sandbox Code Playgroud)

keyboard dart flutter flutter-layout

3
推荐指数
2
解决办法
4919
查看次数

视图重叠,约束布局?

我的Fragment画中有 3 个主要观点ConstraintLayout

  1. 标头
  2. 可滚动内容
  3. 页脚

页眉和页脚应固定位置,中间内容/视图应可滚动。就我而言,中间内容重叠页眉页脚

下面是我的xml代码

   <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout 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"
android:background="@android:color/white"
tools:context=".home.BookingFragment">

<!-- TODO: Update blank fragment layout -->
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="10dp"
        android:gravity="center"
        android:text="REGISTRATION FORM"
        android:textColor="@android:color/black"
        android:textSize="20sp"
        android:textStyle="bold"
        app:layout_constraintTop_toTopOf="parent" />

    <ScrollView
        android:id="@+id/scrollContent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="20dp"
        android:layout_marginBottom="20dp"
        app:layout_constraintBottom_toTopOf="@+id/bookingLayout"
        app:layout_constraintTop_toBottomOf="@+id/title">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


            <TextView
                android:id="@+id/nameTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Name"
                android:textColor="@android:color/black"
                android:textSize="16sp"
                android:textStyle="bold"
                app:layout_constraintTop_toTopOf="parent" />

            <androidx.appcompat.widget.AppCompatEditText
                android:id="@+id/name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp" …
Run Code Online (Sandbox Code Playgroud)

android android-constraintlayout

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

标签栏右溢出 88 像素 flutter tabbar

我正在使用 flutter 开发移动应用程序,我制作了一个图标和文本的选项卡栏,但结果正确溢出了 88 像素\n这是结果的屏幕截图

\n\n

在此输入图像描述

\n\n

这是代码

\n\n
        bottom: new TabBar(controller: controller,\n          tabs: <Widget>[\n            new Tab(\n              child: new Row(\n                  children: <Widget>[\n                    new Icon(Icons.local_hospital,color: Colors.white),\n                    new Text ( "\xd9\x83\xd9\x84\xd8\xa7\xd9\x85",\n                        style:TextStyle(color: Colors.white,\n                        )),\n                  ]),\n            ),\n            new Tab(\n              child: new Row(\n                  children: <Widget>[\n                    new Icon(Icons.school,color: Colors.white),\n                    new Text ( "\xd9\x83\xd9\x84\xd8\xa7\xd9\x85",style:TextStyle(\n                        color: Colors.white\n                    )),\n                  ]),\n            ),\n            new Tab(\n              child: new Row(\n                  children: <Widget>[\n                    new Icon(Icons.account_balance,color: Colors.white),\n                    new Text ( "\xd9\x83\xd9\x84\xd8\xa7\xd9\x85" ,style:TextStyle(\n                        color: Colors.white\n                    )),\n                  ]),\n            ),\n            new Tab(\n              child: new Row(\n                  children: <Widget>[\n …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-layout

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