我是新来的人.只需将我的网格视图居中:
以下是我试过的代码:
@override
Widget build(BuildContext context) {
return new Material(
color: Colors.deepPurpleAccent,
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children:<Widget>[new GridView.count(crossAxisCount: _column,children: new List.generate(_row*_column, (index) {
return new Center(
child: new CellWidget()
);
}),)]
)
);
}
Run Code Online (Sandbox Code Playgroud)
例外情况如下:
I/flutter ( 9925): ??? EXCEPTION CAUGHT BY RENDERING LIBRARY ??????????????????????????????????????????????????????????
I/flutter ( 9925): The following assertion was thrown during performResize():
I/flutter ( 9925): Vertical viewport was given unbounded height.
I/flutter ( 9925): Viewports expand in the scrolling direction to fill their container.In this case, …
Run Code Online (Sandbox Code Playgroud) class GamePage extends StatelessWidget {
int _row;
int _column;
GamePage(this._row,this._column);
@override
Widget build(BuildContext context) {
return new Material(
color: Colors.deepPurpleAccent,
child:new Expanded(
child:new GridView.count(crossAxisCount: _column,children: new List.generate(_row*_column, (index) {
return new Center(
child: new CellWidget()
);
}),) )
);
}
}
Run Code Online (Sandbox Code Playgroud)
附加错误截图.
我必须创建一个返回小部件数组的函数,如下所示:
new GridView.count(crossAxisCount: _column,children: getRandomWidgetArray(),
Run Code Online (Sandbox Code Playgroud)
示例函数如下: -
Widget[] getRandomWidgetArray()
{
Widget[] gameCells;
for(i=0;i<5;i++)
{
gameCells.add(new MyCellWidget(i));
}
return gameCells;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了这个错误: -
我知道如何在没有功能的情况下做到这一点:
children: < Widget >[ new MyCellWidget(0),
new MyCellWidget(1),]
但是我必须使它具有动态功能,因为将来值会发生变化,上面的代码只是原型.颤动的例子非常少.有人可以帮助我.
提前致谢!
最近,我开始使用Constraint布局,但今天使用它遇到了非常奇怪的行为.当我在fragment_holiday.xml中使用RelativeLayout作为root而不是ConstraintLayout时,输出正如预期的那样,但我想知道ConstraintLayout有什么问题.片段,item_row的代码如下
而且我得到了约束布局的输出(并且在滚动它显示不同的beheviour,你可以在我正在分享的截图中看到)---
fragment_holiday.xml
<android.support.constraint.ConstraintLayout 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.thepsi.psidashboard.Fragments.HolidayFragment">
<com.thepsi.psidashboard.CustomViews.CustomDatePicker
android:id="@+id/customDatePicker_holiday"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:dateFormat="MONTH_YEAR"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_view_holiday"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/general_margin_eight_dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/customDatePicker_holiday" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
item_holiday.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content">
<TextView
android:id="@+id/textView25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="24 - January - 2017"
android:textColor="@color/colorPrimaryDark"
/>
<TextView
android:id="@+id/textView26"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="Saturday"
android:layout_alignParentEnd="true"
android:textColor="@color/colorPrimaryDark"
/>
<TextView
android:id="@+id/textView27"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:text="Mahavir Jayanti"
android:textAlignment="center"
android:textColor="@android:color/black"
android:layout_below="@+id/textView25"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
预期设计 -
谁能告诉我这里缺少什么?
代码将解释所有: -
class ResultOverlay extends StatefulWidget {
final bool _isCorrect;
VoidCallback _onTap;
ResultOverlay(this._isCorrect, this._onTap);
......
......
}
Run Code Online (Sandbox Code Playgroud)
它的州级
class ResultOverlayState extends State<ResultOverlay>{
@override
Widget build(BuildContext context) {
........
child: new InkWell(
onTap: () => widget._onTap,
.....
.....
}
Run Code Online (Sandbox Code Playgroud)
传递回调函数: -
new ResultOverlay(isCorrect, () {
() => CallAnswerPage();
})
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?提前致谢 :)
我从我的朋友那里得到了一个颤振项目要完成。
我使用 Android Studio(AS) 作为编辑器。我已经在 AS 中安装了 flutter 和 dart 插件。现在,我通过在 AS 导入 AS 项目开始时选择选项导入了 flutter 项目。然后我不知道为什么它会向我显示设置 Dart SDK 的错误消息(Q1:我的第一个问题是为什么它给出错误我已经有了 dart 插件)。不知何故,我设法从这个链接中获得了 Dart并给出了直到 dart-sdk 文件夹的路径,如截图所示
现在我陷入了这个错误:
Because xxo_tag_xxxls depends on flutter_test any from sdk which doesn't exist (the Flutter SDK is not available), version solving failed.
Run Code Online (Sandbox Code Playgroud)
Flutter 用户应该运行flutter packages get
而不是pub get
.
这是我使用 Flutter 创建的第一个应用程序。我不断收到此错误。
安装版本:
PS D:\> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18362.720], locale en-US)
[?] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[?] Android Studio (version 3.0)
[?] VS Code (version 1.43.2)
[?] Connected device (1 available)
• No issues found!
Run Code Online (Sandbox Code Playgroud)
问题是构建卡在了线上
启动 gradle 守护进程(后续构建会更快)
flutter create myapp
flutter run -v
PS D:\FlutterProjects\myapp> flutter run -d 73e557b65f35 -v
[ +59 …
Run Code Online (Sandbox Code Playgroud) 代码将解释所有:
//modal for list
class MyModal
{
int myField1;
List<MyModal> adjacentNodes;
MyModal(this.myField1)
{
adjacentNodes= new List<MyModal>();
}
}
//pre code
List<MyModal> originalList = new List<MyModal>();
originalList.add(new MyModal(1,"firstBuddy"));
//copying list
List<MyModal> secondList = new List<MyModal>();
secondList.addAll(originalList);
//Modifing copy list
secondList.adjacentNodes.add(new MyModal(2,"anotherBuddy"));
//Also modifies original list
print(originalList[0].childs.length); //prints 1, it should prints 0
Run Code Online (Sandbox Code Playgroud)
如何在第二个列表中执行更改而不影响原始列表?
提前致谢!