Вы можете скопировать и вставить полный код ниже
Вы можете передать snapshot.data[index]
и получить с Map<String, dynamic>
фрагмент кода
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TeamDetails(
teamList: snapshot.data[index],
)));
...
class TeamDetails extends StatelessWidget {
final Map<String, dynamic> teamList;
...
Text("${teamList['strStadiumDescription']}"),
рабочая демонстрация
полный код
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class TeamList extends StatefulWidget {
String category;
TeamList({this.category});
@override
_TeamListState createState() => _TeamListState();
}
class _TeamListState extends State<TeamList> {
Future<List<dynamic>> fetchTeams() async {
var result;
try {
result = await http.get(
"https://www.thesportsdb.com/api/v1/json/1/searchteams.php?t=${widget.category}");
return json.decode(result.body)['teams'];
} catch (e) {
print(e);
}
}
String _teamName(dynamic user) {
return user['strTeam'];
}
String _location(dynamic user) {
return user['strCountry'];
}
String _description(dynamic user) {
return user['strStadiumDescription'];
}
@override
Widget build(BuildContext context) {
return Container(
child: FutureBuilder<List<dynamic>>(
future: fetchTeams(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Center(
child: Text("No Teams found"),
);
}
if (snapshot.hasData) {
return ListView.builder(
shrinkWrap: true,
padding: EdgeInsets.all(8),
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TeamDetails(
teamList: snapshot.data[index],
)));
},
child: Card(
child: Column(
children: <Widget>[
ListTile(
leading: CircleAvatar(
radius: 30,
backgroundImage: NetworkImage(
snapshot.data[index]['strTeamBadge'])),
title: Text(_teamName(snapshot.data[index])),
subtitle: Text(_location(snapshot.data[index])),
)
],
),
),
);
});
}
if (snapshot.hasError) {
return Center(
child: Text(snapshot.error),
);
}
return Center(child: CircularProgressIndicator());
},
),
);
}
}
class TeamDetails extends StatelessWidget {
final Map<String, dynamic> teamList;
const TeamDetails({this.teamList});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0.0,
leading: IconButton(
icon: Icon(
Icons.arrow_back,
color: Colors.black,
),
onPressed: () {
Navigator.pop(context);
},
),
),
body: Column(
children: <Widget>[
Text("${teamList['strStadiumDescription']}"),
],
),
);
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
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> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: TeamList(
category: "football",
),
);
}
}