Flutter 中的重叠 CoverFlow
Overlapped CoverFlow in Flutter
我正在尝试使用 flutter 创建旧的 Iphone Coverflow 设计。我试过使用对齐宽度因子的列表视图。但它只以一种方式重叠。
Container(
height: 300,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 25,
itemBuilder: (BuildContext context, int position) => Align(
widthFactor: 0.8,
child: Container(
height: 200,
width: 120,
color: Colors.green.withOpacity(0.4),
child: Center(child: Text(position.toString())),
),
),
),
),
我需要实现图片上的设计。我怎样才能做到这一点?
我已经尝试了所有我认为可用的包,比如 PreloadPageview、finite coverflow、simple coverflow、perspective pageview 等等。我可以实现转换,但不能同时实现横向和水平滚动的重叠
这与您的要求非常相似,perspective_pageview:
Container(
child: Center(
// Adding Child Widget of Perspective PageView
child: PerspectivePageView(
hasShadow: true, // Enable-Disable Shadow
shadowColor: Colors.black12, // Change Color
aspectRatio: PVAspectRatio.ONE_ONE, // Aspect Ratio of 1:1 (Default)
children: <Widget>[
GestureDetector(
onTap: () {
debugPrint("Statement One");
},
child: Container(
color: Colors.red,
),
),
GestureDetector(
onTap: () {
debugPrint("Statement Two");
},
child: Container(
color: Colors.green,
),
)
],
),
),
),
这不是你想要的重叠coverflow。
这是我的包裹。
https://pub.dev/packages/coverflow
我尝试实现重叠小部件...失败...
import 'package:coverflow/coverflow.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
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> {
final List<String> titles = [
"Title1",
"Title2",
"Title3",
"Title4",
"Title5",
"Title6",
"Title7",
"Title8",
];
final List<Widget> images = [
Container(
color: Colors.red,
),
Container(
color: Colors.yellow,
),
Container(
color: Colors.black,
),
Container(
color: Colors.cyan,
),
Container(
color: Colors.blue,
),
Container(
color: Colors.grey,
),
Container(
color: Colors.green,
),
Container(
color: Colors.amber,
),
];
List<Widget> images2 = [
Image.asset('assets/1.jpg'),
Image.asset('assets/2.jpg'),
Image.asset('assets/3.jpg'),
Image.asset('assets/4.jpg'),
Image.asset('assets/5.jpg'),
Image.asset('assets/6.jpg'),
Image.asset('assets/7.jpg'),
Image.asset('assets/8.jpg'),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SizedBox(
height: 200,
child: CoverFlow(
images: images2,
titles: titles,
textStyle: TextStyle(color: Colors.red),
),
),
),
);
}
}
我正在尝试使用 flutter 创建旧的 Iphone Coverflow 设计。我试过使用对齐宽度因子的列表视图。但它只以一种方式重叠。
Container(
height: 300,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 25,
itemBuilder: (BuildContext context, int position) => Align(
widthFactor: 0.8,
child: Container(
height: 200,
width: 120,
color: Colors.green.withOpacity(0.4),
child: Center(child: Text(position.toString())),
),
),
),
),
这与您的要求非常相似,perspective_pageview:
Container(
child: Center(
// Adding Child Widget of Perspective PageView
child: PerspectivePageView(
hasShadow: true, // Enable-Disable Shadow
shadowColor: Colors.black12, // Change Color
aspectRatio: PVAspectRatio.ONE_ONE, // Aspect Ratio of 1:1 (Default)
children: <Widget>[
GestureDetector(
onTap: () {
debugPrint("Statement One");
},
child: Container(
color: Colors.red,
),
),
GestureDetector(
onTap: () {
debugPrint("Statement Two");
},
child: Container(
color: Colors.green,
),
)
],
),
),
),
这不是你想要的重叠coverflow。
这是我的包裹。 https://pub.dev/packages/coverflow
我尝试实现重叠小部件...失败...
import 'package:coverflow/coverflow.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
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> {
final List<String> titles = [
"Title1",
"Title2",
"Title3",
"Title4",
"Title5",
"Title6",
"Title7",
"Title8",
];
final List<Widget> images = [
Container(
color: Colors.red,
),
Container(
color: Colors.yellow,
),
Container(
color: Colors.black,
),
Container(
color: Colors.cyan,
),
Container(
color: Colors.blue,
),
Container(
color: Colors.grey,
),
Container(
color: Colors.green,
),
Container(
color: Colors.amber,
),
];
List<Widget> images2 = [
Image.asset('assets/1.jpg'),
Image.asset('assets/2.jpg'),
Image.asset('assets/3.jpg'),
Image.asset('assets/4.jpg'),
Image.asset('assets/5.jpg'),
Image.asset('assets/6.jpg'),
Image.asset('assets/7.jpg'),
Image.asset('assets/8.jpg'),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SizedBox(
height: 200,
child: CoverFlow(
images: images2,
titles: titles,
textStyle: TextStyle(color: Colors.red),
),
),
),
);
}
}