gpt4 book ai didi

Flutter 列小部件 : childs with different heights

转载 作者:IT王子 更新时间:2023-10-29 06:54:33 24 4
gpt4 key购买 nike

我正在尝试创建一个小型测试应用程序,其中有一个较大的中央区域,我将在该区域上渲染图像,而较小的底部区域将包含一个水平可滚动的小部件列表。这是代码:

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'dart:isolate';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:photo_app_ui_test/fxmanager/fx_manager.dart';

////
void main() {
runApp(SampleApp());
}

class SampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Sample App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SampleAppPage(),
);
}
}

class SampleAppPage extends StatefulWidget {
SampleAppPage({Key key}) : super(key: key);

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

class _SampleAppPageState extends State<SampleAppPage> {
FxManager fxManager;
bool showLoadingDialog = true;

@override
void initState() {
super.initState();
//loadData();
fxManager = FxManager();
fxManager.init().then( (dynamic) => initInterface() );
}


void initInterface(){
setState(() {
showLoadingDialog = false;
});
}

getBody() {
if (showLoadingDialog) {
return getProgressDialog();
} else {
return getEffectsWidget();//getListView();
}
}

getProgressDialog() {
return Center(child: CircularProgressIndicator());
}

getEffectsWidget() {
return

Column(
children: <Widget>[

Expanded(child: Container(color: Color.fromARGB(255, 255, 0, 0),
child: Center(child: Text("Image")))),
Flexible( child: Container(
color: Color.fromARGB(255, 0, 255, 0),
child: ListView(
scrollDirection: Axis.horizontal,
children: _getListData()
)))
]);
}

_getListData() {
List<Widget> widgets = [];
for (int i = 0; i < 100; i++) {
widgets.add(Padding(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
/*
Expanded(
child: Container(),
),*/
FlatButton(
onPressed: () => {},
color: Colors.orange,
padding: EdgeInsets.all(10.0),
child: Column(
// Replace with a Row for horizontal icon + text
children: <Widget>[Icon(Icons.add), Text("Add")],
)),
],
)));
}
return widgets;
}


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Sample App"),
),
body: getBody());
}


}

产生这个结果:

enter image description here

我想让绿框的高度尽可能小:

enter image description here

如果 ListView 小部件是 Column 小部件的直接子级,通常的 Horizo​​ntal viewport was given unbounded height 异常将被抛出。所以我必须将它嵌入到 FlexibleExpanded 中。

最佳答案

期望的输出:

getEffectsWidget() {
return Column(children: <Widget>[
Expanded(
child: Container(
color: Color.fromARGB(255, 255, 0, 0),
child: Center(child: Text("Image")))),

Container(
color: Color.fromARGB(255, 0, 255, 0),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: _getListData(),
),
),
)
]);
}

static _getListData() {
List<Widget> widgets = [];
for (int i = 0; i < 100; i++) {
widgets.add(Padding(
padding: EdgeInsets.only(right: 10.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
/*
Expanded(
child: Container(),
),*/
FlatButton(
onPressed: () => {},
color: Colors.orange,
padding: EdgeInsets.all(10.0),
child: Column(
mainAxisSize: MainAxisSize.min,
// Replace with a Row for horizontal icon + text
children: <Widget>[Icon(Icons.add), Text("Add")],
)),
],
)));
}
return widgets;
}

关于Flutter 列小部件 : childs with different heights,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53021195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com