だから私はしばらくフラッターを学んでいて、これで立ち往生しています。初心者の質問でしたら申し訳ありません。現在、Card Tab のようなものを構築しようとしています。情報とウィジェットはカードに保存されます。
複数のカードスタックがあり、左右にスワイプしてナビゲートする Tinder のようなものを想像してみてください。
私はそれを作成する予定ですが、ボタンで新しいカードを追加/レンダリングする方法を見つけることができないようです.
リストに何かを追加するようなものです。Flutter は、リストに追加する ListView ビルダーを使用します。しかし、TabBarView ビルダーはありません。これはどうしようもないことでしょうか。タブ内にリストを入れてみましたが、それでも同じではありません。
ここで、私の意味を伝えるのに役立ついくつかの基本的な骨組みを作成しました。したがって、カードは左右にスワイプされ、appBar にカードを追加するためのボタンがあります。長さは現在 2 で、3 番目のカードをレンダリングするボタンが必要でした。これは可能ですか?
前もって感謝します!
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new CardStack(),
));
}
class CardStack extends StatefulWidget {
@override
_MainState createState() => new _MainState();
}
class _MainState extends State<CardStack> with SingleTickerProviderStateMixin {
TabController _cardController;
@override
void initState() {
super.initState();
_cardController = new TabController(vsync: this, length: 2);
}
@override
void dispose() {
_cardController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.grey[300],
appBar: new AppBar(
actions: <Widget>[
new IconButton(
icon: const Icon(Icons.add),
tooltip: 'Add Tabs',
onPressed: null,
),
],
title: new Text("Title Here"),
bottom: new PreferredSize(
preferredSize: const Size.fromHeight(20.0),
child: new Theme(
data: Theme.of(context).copyWith(accentColor: Colors.grey),
child: new Container(
height: 50.0,
alignment: Alignment.center,
child: new TabPageSelector(controller: _cardController),
),
)
)
),
body: new TabBarView(
controller: _cardController,
children: <Widget>[
new Center(
child: new Card(
child: new Container(
height: 450.0,
width: 300.0,
child: new IconButton(
icon: new Icon(Icons.favorite, size: 100.0),
tooltip: 'Favorited',
onPressed: null,
)
),
),
),
new Center(
child: new Card(
child: new Container(
height: 450.0,
width: 300.0,
child: new IconButton(
icon: new Icon(Icons.local_pizza, size: 50.0,),
tooltip: 'Pizza',
onPressed: null,
)
),
),
),
],
),
);
}
}