I am not entirely sure what you are trying to do here, but Few things. PageView
widget expands to the maximum allowed space by default, so you don't need the Expanded or Center widget around it.
Second, I don't know why you would want to wrap Card
widget with ListTile
. You certainly can, but that's not how ListTile and Card are designed.
Third, because PageView widget can expand, it needs some size constraints, so it cannot be put inside a infinitely large widget like ListView, so you can remove that, and here is what I have. I hope it is close to what you were looking for.
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool swap = true;
int _index = 0;
@override
Widget build(BuildContext context) {
Widget swapWidget;
if (swap) {
swapWidget = PageView.builder(
itemCount: 2,
controller: PageController(viewportFraction: 0.95),
itemBuilder: (_, i) {
return Transform.scale(
scale: i == _index ? 1 : 0.9,
child: Card(
elevation: 6,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Center(
child: Text(
"Card ${i + 1}",
style: TextStyle(fontSize: 32),
),
),
),
);
},
);
} else {
swapWidget = Card(child: Text('Nothing To show'));
}
return Scaffold(
body: swapWidget,
);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…