[英]Flutter Listview where to onTap and how to make text and listview block larger?
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:async';
class SearchView extends StatefulWidget {
@override
_SearchViewState createState() => _SearchViewState();
}
class _SearchViewState extends State<SearchView> {
List data = [];
Future<String> getData() async {
http.Response res = await http
.get(Uri.parse("https://gcse.doky.space/api/schedule/buildings"));
this.setState(() {
data = jsonDecode(res.body)["result"];
});
return "success";
}
@override
void initState() {
super.initState();
this.getData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('건물 선택')),
body: new ListView.builder(
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return new Card(
child: new Text(data[index]),
);
},
),
);
}
}
我正在制作教室預訂系統。
但是每個列表視圖塊都太小了,所以很難點擊。
如何使文本和塊更大?
我應該在哪里放 onTap 以使 listview 可觸摸?
我可以建議您使用ListTile而不是 Text 嗎?
ListTile(
onTap: _itemtapped,
title: Text(myText)
)
void _itemtapped() {
// do you thing here
}
使用InkWell
小部件。 它會給你一個很好的點擊效果。
InkWell(
child: Text(data[index]),
onTap: _onTap,
)
並隨時實施:
void _onTap() {}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.