Flutter Listview 在哪里 onTap 以及如何使文本和列表视图块变大?
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 放在哪里才能使列表视图可触摸?
我可以建议您使用 ListTile 而不是文本吗?
ListTile(
onTap: _itemtapped,
title: Text(myText)
)
void _itemtapped() {
// do you thing here
}
使用InkWell
小部件。它会给你一个很好的点击效果。
InkWell(
child: Text(data[index]),
onTap: _onTap,
)
并点击实现:
void _onTap() {}
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 放在哪里才能使列表视图可触摸?
我可以建议您使用 ListTile 而不是文本吗?
ListTile(
onTap: _itemtapped,
title: Text(myText)
)
void _itemtapped() {
// do you thing here
}
使用InkWell
小部件。它会给你一个很好的点击效果。
InkWell(
child: Text(data[index]),
onTap: _onTap,
)
并点击实现:
void _onTap() {}