gpt4 book ai didi

flutter - 在使用滚动方向 : Axis. 水平使 ListView.builder 水平时遇到困难

转载 作者:IT王子 更新时间:2023-10-29 07:02:20 25 4
gpt4 key购买 nike

我正在尝试在 Flexible 中使用 ListView.builder。它在滚动方向上工作正常:Axis.vertical 当我将其更改为滚动方向时:Axis.horizo​​ntal。它不工作

 List modeData = [
{'modeName': 'VAN', 'modeTime': '3 min', 'modeIcon': Icons.android },
{'modeName': 'VAN', 'modeTime': '3 min', 'modeIcon': Icons.android },

];

callback(data) {}

int _selectedIndex = 0;

_onSelected ( int index ) {
setState(() => _selectedIndex = index);
}

@override
Widget build(BuildContext context) {

return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: modeData.length,
itemBuilder: (context, index) => Container(
child: ListTile(
onTap: () => _onSelected(index),
// title: TravelMode(modeName, modeIcon, modeTime, isSelected),
title: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(modeData[index]['modeTime']),
Container(
decoration: new BoxDecoration(enter code here
color: _selectedIndex != null && _selectedIndex ==
index ? Colors.blue : null,
borderRadius: new BorderRadius.all(const
Radius.circular(40.0))),
child: IconButton(
icon: Icon(modeData[index]['modeIcon']),
color: Colors.black38,

),
),
Text(modeData[index]['modeName'])
],
),
),
)

);
}
}


Flexible(
flex: 2,
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child:
TravelModesList()),],),
),

我在这个 Flexible enter image description here 中调用它试图获得 Ola Cab 中显示的车辆列表在此处输入代码

最佳答案

这是一个工作示例

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

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

final String title;

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

class _MyHomePageState extends State<MyHomePage> {
List modeData = [
{'modeName': 'VAN', 'modeTime': '3 min', 'modeIcon': Icons.android},
{'modeName': 'VAN', 'modeTime': '3 min', 'modeIcon': Icons.android},
];

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: modeData.length,
itemBuilder: (context, index) {
return Padding(padding: EdgeInsets.only(left: 10.0,), child: Column(
children: [
Text(modeData[index]['modeTime']),
Container(
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(
Radius.circular(
40.0,
),
),
),
child: IconButton(
icon: Icon(modeData[index]['modeIcon']),
color: Colors.black38,
),
),
],
),);
},
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}

screenshot

关于flutter - 在使用滚动方向 : Axis. 水平使 ListView.builder 水平时遇到困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57056778/

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