Flutter 旋转滑翔机新闻页面在颤振
我正在做一个关于Flutter的报纸网站,但是每当我尝试实现CarouselSlider时,根据软件包,它都无法访问列表,有人知道我如何使用与此代码相同的实现来实现这个carousel吗 名单公告:Flutter 旋转滑翔机新闻页面在颤振,flutter,Flutter,我正在做一个关于Flutter的报纸网站,但是每当我尝试实现CarouselSlider时,根据软件包,它都无法访问列表,有人知道我如何使用与此代码相同的实现来实现这个carousel吗 名单公告: class ArticlesPosts { String title; String titleHome; String subtitle; String pic; String author; String notice; String data; Article
class ArticlesPosts {
String title;
String titleHome;
String subtitle;
String pic;
String author;
String notice;
String data;
ArticlesPosts({
this.title,
this.titleHome,
this.subtitle,
this.author,
this.pic,
this.notice,
this.data,
});
}
var allPosts = [
ArticlesPosts(
title:
'XXXXXXX',
titleHome: 'XXXXXXXXXXXXX',
subtitle: 'sssssssssssssssssssssssssssssssssssssssssssssss',
author: 'nome',
pic: 'assets/1.jpg',
notice:
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
data: 'Published in 14/04/2021',
),
];
主页:
import 'package:flutter/material.dart';
import 'package:flutter_application_1/views/home/posts.dart';
import 'articlesDetails.dart';
class MainScreen extends StatelessWidget {
final posts = allPosts;
@override
Widget build(BuildContext context) {
return ListView(
children: [
Column(children: [
SizedBox(height: 20),
Padding(
padding: EdgeInsets.only(left: 15.0),
child: Text(
"RobSIC News",
style: TextStyle(
fontWeight: FontWeight.w800, height: 3.0, fontSize: 26),
),
),
SizedBox(height: 30),
Container(
height: MediaQuery.of(context).size.height - 200,
child: GridView.count(
crossAxisCount: 1,
crossAxisSpacing: 0.5,
mainAxisSpacing: 0.5,
childAspectRatio: 4,
primary: false,
children: [
...posts.map((e) {
return buildPostsGrid(e, context);
}).toList()
]),
),
])
],
);
}
buildPostsGrid(ArticlesPosts posts, BuildContext context) {
return Card(
elevation: 9,
child: FlatButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ArticlesDetail(selectedPosts: posts)));
},
child: Padding(
padding: EdgeInsets.all(5.0),
child: Stack(children: [
Container(height: 400, width: 900.0, color: Colors.transparent),
Positioned(
left: 30.0,
top: 30.0,
child: Container(
height: 30.0,
width: 40.0,
decoration: BoxDecoration(boxShadow: [
BoxShadow(
blurRadius: 7.0,
color: Colors.grey.withOpacity(0.75),
offset: Offset(5, 25),
spreadRadius: 12.0)
]))),
Positioned(
left: 12.0,
top: 15.0,
child: Hero(
tag: posts.pic,
child: Container(
height: 190.0,
width: 1000,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0),
image: DecorationImage(
image: AssetImage(posts.pic),
fit: BoxFit.cover))))),
Positioned(
left: 15.0,
top: 145,
child: Column(children: [
Text(posts.titleHome,
style: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.white70,
height: 1.6,
fontSize: 24)),
])),
Positioned(
left: 15.0,
top: 179,
child: Column(children: [
Text(posts.subtitle,
style: TextStyle(
fontWeight: FontWeight.w400,
color: Colors.white,
height: 1.2,
fontSize: 20)),
])),
Positioned(
left: 740.0,
top: 210,
child: Column(children: [
Text(posts.data,
style: TextStyle(
fontWeight: FontWeight.w400,
height: 1.2,
fontSize: 14)),
])),
Positioned(
left: 15.0,
top: 210,
child: Column(children: [
Text(posts.author,
style: TextStyle(
fontWeight: FontWeight.w400,
height: 1.2,
fontSize: 14)),
])),
]),
)),
);
}
}
新闻页详情
import 'package:flutter/material.dart';
import 'package:flutter_application_1/views/home/posts.dart';
class ArticlesDetail extends StatefulWidget {
final ArticlesPosts selectedPosts;
const ArticlesDetail({Key key, this.selectedPosts}) : super(key: key);
@override
_ArticlesDetailState createState() => _ArticlesDetailState();
}
class _ArticlesDetailState extends State<ArticlesDetail> {
final posts = allPosts;
@override
Widget build(
BuildContext context,
) {
return Stack(
children: [
Container(
padding: EdgeInsets.only(
top: 25,
bottom: 16,
left: 16,
right: 16,
),
margin: EdgeInsets.only(top: 16),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(17),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 10,
offset: Offset(0, 10),
)
]),
child: Stack(children: [
ListView(
children: [
SizedBox(height: 10),
Positioned(
child: Container(
height: 90,
width: 300,
child: Text(widget.selectedPosts.title,
style: TextStyle(
fontSize: 26, fontWeight: FontWeight.w600)),
),
),
SizedBox(height: 10),
Positioned(
child: Container(
height: 50,
width: 300,
child: Text(widget.selectedPosts.subtitle,
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.w300)),
),
),
SizedBox(height: 20),
Positioned(
child: Container(
height: 50,
width: 300,
child: Text(
'_______________________________________________________________________________________________________________________',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w100,
color: Colors.black12)),
),
),
SizedBox(height: 20),
Positioned(
child: Container(
height: 400,
width: 200,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(widget.selectedPosts.pic))))),
SizedBox(height: 50),
Positioned(
child: Container(
height: 150,
width: 300,
child: Text(widget.selectedPosts.notice,
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.w400)),
),
),
Align(
alignment: Alignment.bottomRight,
child: FlatButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Confirm')))
],
)
]),
)
],
);
}
}
导入“包装:颤振/材料.省道”;
导入“包:flatter_应用程序_1/views/home/posts.dart”;
类ArticlesDetail扩展StatefulWidget{
最后一篇文章刊登选定的帖子;
constarticlesdetail({Key,this.selectedPosts}):super(Key:Key);
@凌驾
_ArticlesDetailState createState()=>\u ArticlesDetailState();
}
类_ArticlesDetailState扩展状态{
最后职位=所有职位;
@凌驾
小部件构建(
构建上下文上下文,
) {
返回堆栈(
儿童:[
容器(
填充:仅限边缘设置(
前25名,
底图:16,
左:16,
右:16,
),
页边距:仅限边缘集(顶部:16),
装饰:盒子装饰(
颜色:颜色,白色,
形状:BoxShape.rectangle,
边界半径:边界半径。圆形(17),
boxShadow:[
箱形阴影(
颜色:颜色。黑色,
半径:10,
偏移量:偏移量(0,10),
)
]),
子:堆栈(子:[
列表视图(
儿童:[
尺寸箱(高度:10),
定位(
子:容器(
身高:90,
宽度:300,
子项:文本(widget.selectedPosts.title,
样式:TextStyle(
fontSize:26,fontWeight:fontWeight.w600),
),
),
尺寸箱(高度:10),
定位(
子:容器(
身高:50,
宽度:300,
子项:文本(widget.selectedPosts.subtitle,
样式:TextStyle(
fontSize:18,fontWeight:fontWeight.w300),
),
),
尺寸箱(高度:20),
定位(
子:容器(
身高:50,
宽度:300,
子:文本(
'_______________________________________________________________________________________________________________________',
样式:TextStyle(
尺码:18,
fontWeight:fontWeight.w100,
颜色:颜色。黑色12),
),
),
尺寸箱(高度:20),
定位(
子:容器(
身高:400,
宽度:200,
装饰:盒子装饰(
图像:装饰图像(
图片:AssetImage(widget.selectedPosts.pic()())(,
尺寸箱(高度:50),
定位(
子:容器(
身高:150,
宽度:300,
子项:文本(widget.selectedPosts.notice,
样式:TextStyle(
fontSize:18,fontWeight:fontWeight.w400),
),
),
对齐(
对齐:对齐。右下角,
孩子:扁平按钮(
已按下:(){
Navigator.pop(上下文);
},
子项:文本('Confirm'))
],
)
]),
)
],
);
}
}