Flutter 如何获取列表信息<;地图>;到另一个飘动的屏幕?
我是颤振方面的新手,我正在为我的大学使用该框架进行一个项目。我有一个使用列表的屏幕,正在按我的需要工作:Flutter 如何获取列表信息<;地图>;到另一个飘动的屏幕?,flutter,dart,Flutter,Dart,我是颤振方面的新手,我正在为我的大学使用该框架进行一个项目。我有一个使用列表的屏幕,正在按我的需要工作: class BarberPage extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: BarberList(), ), ); } } class
class BarberPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: BarberList(),
),
);
}
}
class BarberList extends StatefulWidget {
BarberList({Key key}) : super(key: key);
// static final String path = "lib/src/pages/lists/list2.dart";
_BarberListState createState() => _BarberListState();
}
class _BarberListState extends State<BarberList> {
final TextStyle dropdownMenuItem =
TextStyle(color: Colors.black, fontSize: 18);
final primary = Color(0xFF63736B);
final secondary = Color(0xFF0C0E0B);
final green = Color(0xFF79FF00);
final List<Map> barberLists = [
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
];
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: Scaffold(
backgroundColor: Color(0xfff0f0f0),
body: SingleChildScrollView(
child: Container(
height: MediaQuery
.of(context)
.size
.height,
width: MediaQuery
.of(context)
.size
.width,
child: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 145),
height: MediaQuery
.of(context)
.size
.height,
width: double.infinity,
child: ListView.builder(
itemCount: barberLists.length,
itemBuilder: (BuildContext context, int index) {
return buildList(context, index);
}),
),
Container(
height: 140,
width: double.infinity,
decoration: BoxDecoration(
color: green,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30))),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_back,
color: Colors.white,
),
),
Text(
"Barbearias",
style: TextStyle(color: Colors.white, fontSize: 24),
),
IconButton(
onPressed: () {},
icon: Icon(
Icons.filter_list,
color: Colors.white,
),
),
],
),
),
),
Container(
child: Column(
children: <Widget>[
SizedBox(
height: 110,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Material(
elevation: 5.0,
borderRadius: BorderRadius.all(Radius.circular(30)),
child: TextField(
// controller: TextEditingController(text: locations[0]),
cursorColor: Theme
.of(context)
.primaryColor,
style: dropdownMenuItem,
decoration: InputDecoration(
hintText: "Procurar Barbearias",
hintStyle: TextStyle(
color: Colors.black38, fontSize: 16),
prefixIcon: Material(
elevation: 0.0,
borderRadius:
BorderRadius.all(Radius.circular(30)),
child: Icon(Icons.search),
),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
horizontal: 25, vertical: 13)),
),
),
),
],
),
)
],
),
),
),
),
);
}
Widget buildList(BuildContext context, int index) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: Colors.white,
),
width: double.infinity,
height: 120,
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
child: GestureDetector(
onTap: () {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(index.toString()),
));
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 60,
height: 60,
margin: EdgeInsets.only(right: 15, top: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
border: Border.all(width: 3, color: secondary),
image: DecorationImage(
image: CachedNetworkImageProvider(
barberLists[index]['logoText']),
fit: BoxFit.fill),
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
barberLists[index]['name'],
style: TextStyle(
color: primary,
fontWeight: FontWeight.bold,
fontSize: 18),
),
SizedBox(
height: 6,
),
Row(
children: <Widget>[
Icon(
Icons.location_on,
color: secondary,
size: 20,
),
SizedBox(
width: 5,
),
Text(barberLists[index]['location'],
style: TextStyle(
color: primary, fontSize: 13, letterSpacing: .3)),
],
),
SizedBox(
height: 6,
),
Row(
children: <Widget>[
Icon(
Icons.calendar_today,
color: secondary,
size: 20,
),
SizedBox(
width: 5,
),
Text(barberLists[index]['type'],
style: TextStyle(
color: primary, fontSize: 13, letterSpacing: .3)),
],
),
SizedBox(
height: 6,
),
Row(
children: <Widget>[
Icon(
Icons.call_end,
color: secondary,
size: 20,
),
SizedBox(
width: 5,
),
Text(barberLists[index]['phone'],
style: TextStyle(
color: primary, fontSize: 13, letterSpacing: .3)),
],
),
],
),
)
],
),
),
);
}
}
class BarberPage扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
正文:BarberList(),
),
);
}
}
类BarberList扩展了StatefulWidget{
BarberList({Key}):超级(Key:Key);
//静态最终字符串路径=“lib/src/pages/lists/list2.dart”;
_BarberListState createState()=>\u BarberListState();
}
类_BarberListState扩展了状态{
最终文本样式下拉菜单项=
TextStyle(颜色:Colors.black,字体大小:18);
最终原色=颜色(0xFF63736B);
最终二次=颜色(0xFF0C0E0B);
最终绿色=颜色(0xFF79FF00);
最终列表列表=[
{
“名称”:“巴比里亚岛”,
“地点”:“Rua Paraná,184-Cidade de Deus”,
“类型”:“de09hás 18h-Seg.a Sex.”,
“电话”:(37)99122-3338,
“logoText”:
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
“名称”:“巴比里亚岛”,
“地点”:“Rua Paraná,184-Cidade de Deus”,
“类型”:“de09hás 18h-Seg.a Sex.”,
“电话”:(37)99122-3338,
“logoText”:
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
“名称”:“巴比里亚岛”,
“地点”:“Rua Paraná,184-Cidade de Deus”,
“类型”:“de09hás 18h-Seg.a Sex.”,
“电话”:(37)99122-3338,
“logoText”:
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
“名称”:“巴比里亚岛”,
“地点”:“Rua Paraná,184-Cidade de Deus”,
“类型”:“de09hás 18h-Seg.a Sex.”,
“电话”:(37)99122-3338,
“logoText”:
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
“名称”:“巴比里亚岛”,
“地点”:“Rua Paraná,184-Cidade de Deus”,
“类型”:“de09hás 18h-Seg.a Sex.”,
“电话”:(37)99122-3338,
“logoText”:
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
“名称”:“巴比里亚岛”,
“地点”:“Rua Paraná,184-Cidade de Deus”,
“类型”:“de09hás 18h-Seg.a Sex.”,
“电话”:(37)99122-3338,
“logoText”:
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
“名称”:“巴比里亚岛”,
“地点”:“Rua Paraná,184-Cidade de Deus”,
“类型”:“de09hás 18h-Seg.a Sex.”,
“电话”:(37)99122-3338,
“logoText”:
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
“名称”:“巴比里亚岛”,
“地点”:“Rua Paraná,184-Cidade de Deus”,
“类型”:“de09hás 18h-Seg.a Sex.”,
“电话”:(37)99122-3338,
“logoText”:
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
];
@凌驾
小部件构建(构建上下文){
返回新材料PP(
家:脚手架(
背景颜色:颜色(0xFFF0),
正文:SingleChildScrollView(
子:容器(
高度:MediaQuery
.of(上下文)
.尺寸
.身高,
宽度:MediaQuery
.of(上下文)
.尺寸
.宽度,
子:堆栈(
儿童:[
容器(
填充:仅限边缘设置(顶部:145),
高度:MediaQuery
.of(上下文)
.尺寸
.身高,
宽度:double.infinity,
子项:ListView.builder(
itemCount:BarberList.length,
itemBuilder:(构建上下文,int索引){
返回构建列表(上下文、索引);
}),
),
容器(
身高:140,
宽度:double.infinity,
装饰:盒子装饰(
颜色:绿色,
borderRadius:仅限borderRadius(
左下角:半径。圆形(30),
右下角:半径。圆形(30)),
孩子:填充(
填充:常量边集。对称(水平:30),
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
图标按钮(
已按下:(){
Navigator.pop(上下文);
},
图标:图标(
Icons.arrow_back,
颜色:颜色,白色,
),
),
正文(
“巴比里亚”,
样式:TextStyle(颜色:Colors.white,字体大小:24),
),
图标按钮(
按下:(){},
图标:图标(
Icons.filter_列表,
颜色:颜色,白色,
),
),
],
),
),
),
容器(
子:列(
儿童:[
大小盒子(
身高:110,
),
填充物(
填充:边缘组。对称(水平:20),
儿童:材料(
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailScreen(detailData: barberLists[index]),
),
);
...
class DetailScreen extends StatelessWidget {
final Map detailData;
DetailScreen({Key key, @required this.detailData}) : super(key: key);
import 'package:flutter/material.dart';
//import 'package:cached_network_image/cached_network_image.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(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: BarberList(),
);
}
}
class BarberList extends StatefulWidget {
BarberList({Key key}) : super(key: key);
// static final String path = "lib/src/pages/lists/list2.dart";
_BarberListState createState() => _BarberListState();
}
class _BarberListState extends State<BarberList> {
final TextStyle dropdownMenuItem =
TextStyle(color: Colors.black, fontSize: 18);
final primary = Color(0xFF63736B);
final secondary = Color(0xFF0C0E0B);
final green = Color(0xFF79FF00);
final List<Map> barberLists = [
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
{
"name": "Barbearia do PA",
"location": "Rua Paraná, 184 - Cidade de Deus",
"type": "De 09h ás 18h - Seg. à Sex.",
"phone": "(37) 99122-3338",
"logoText":
"https://cdn.pixabay.com/photo/2017/01/13/01/22/rocket-1976107_960_720.png"
},
];
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: Scaffold(
backgroundColor: Color(0xfff0f0f0),
body: SingleChildScrollView(
child: Container(
height: MediaQuery
.of(context)
.size
.height,
width: MediaQuery
.of(context)
.size
.width,
child: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 145),
height: MediaQuery
.of(context)
.size
.height,
width: double.infinity,
child: ListView.builder(
itemCount: barberLists.length,
itemBuilder: (BuildContext context, int index) {
return buildList(context, index);
}),
),
Container(
height: 140,
width: double.infinity,
decoration: BoxDecoration(
color: green,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30))),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_back,
color: Colors.white,
),
),
Text(
"Barbearias",
style: TextStyle(color: Colors.white, fontSize: 24),
),
IconButton(
onPressed: () {},
icon: Icon(
Icons.filter_list,
color: Colors.white,
),
),
],
),
),
),
Container(
child: Column(
children: <Widget>[
SizedBox(
height: 110,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Material(
elevation: 5.0,
borderRadius: BorderRadius.all(Radius.circular(30)),
child: TextField(
// controller: TextEditingController(text: locations[0]),
cursorColor: Theme
.of(context)
.primaryColor,
style: dropdownMenuItem,
decoration: InputDecoration(
hintText: "Procurar Barbearias",
hintStyle: TextStyle(
color: Colors.black38, fontSize: 16),
prefixIcon: Material(
elevation: 0.0,
borderRadius:
BorderRadius.all(Radius.circular(30)),
child: Icon(Icons.search),
),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
horizontal: 25, vertical: 13)),
),
),
),
],
),
)
],
),
),
),
),
);
}
Widget buildList(BuildContext context, int index) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: Colors.white,
),
width: double.infinity,
height: 120,
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
child: GestureDetector(
onTap: () {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(index.toString()),
));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailScreen(detailData: barberLists[index]),
),
);
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 60,
height: 60,
margin: EdgeInsets.only(right: 15, top: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
border: Border.all(width: 3, color: secondary),
/*image: DecorationImage(
image: CachedNetworkImageProvider(
barberLists[index]['logoText']),
fit: BoxFit.fill),*/
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
barberLists[index]['name'],
style: TextStyle(
color: primary,
fontWeight: FontWeight.bold,
fontSize: 18),
),
SizedBox(
height: 6,
),
Row(
children: <Widget>[
Icon(
Icons.location_on,
color: secondary,
size: 20,
),
SizedBox(
width: 5,
),
Text(barberLists[index]['location'],
style: TextStyle(
color: primary, fontSize: 13, letterSpacing: .3)),
],
),
SizedBox(
height: 6,
),
Row(
children: <Widget>[
Icon(
Icons.calendar_today,
color: secondary,
size: 20,
),
SizedBox(
width: 5,
),
Text(barberLists[index]['type'],
style: TextStyle(
color: primary, fontSize: 13, letterSpacing: .3)),
],
),
SizedBox(
height: 6,
),
Row(
children: <Widget>[
Icon(
Icons.call_end,
color: secondary,
size: 20,
),
SizedBox(
width: 5,
),
Text(barberLists[index]['phone'],
style: TextStyle(
color: primary, fontSize: 13, letterSpacing: .3)),
],
),
],
),
)
],
),
),
);
}
}
class DetailScreen extends StatelessWidget {
// Declare a field that holds the Todo.
final Map detailData;
// In the constructor, require a Todo.
DetailScreen({Key key, @required this.detailData}) : super(key: key);
@override
Widget build(BuildContext context) {
// Use the Todo to create the UI.
return Scaffold(
appBar: AppBar(
title: Text(detailData["name"]),
),
body: Padding(
padding: EdgeInsets.all(16.0),
child: Text(detailData["location"]),
),
);
}
}