gpt4 book ai didi

flutter - 我想在我的flutter应用程序中通过onPressed方法生成卡。谁能给我看一个路线图…?

转载 作者:行者123 更新时间:2023-12-03 02:59:03 24 4
gpt4 key购买 nike

我已经在页面中创建了listview.builder。为此,我设计了我的卡。现在,我想通过单击 float 操作按钮中的onpressed方法在Listveiw.buider中一张一张生成卡片。我应该在压缩后的内容中写哪种方法/功能?以及如何生成卡片以及应该在itemCount和itemBuilder中进行哪些更改。我需要那个路线图。谢谢。

ListView.builder(
itemCount: 5,
itemBuilder: (context, index) {
return Dismissible(
key:Key(null),
direction: DismissDirection.startToEnd,
onDismissed: (direction) {},
confirmDismiss: (direction) {
return showDialog(
context: context, builder: (_) => DeleteCard());
},
background: Container(
color: Colors.red,
padding: EdgeInsets.only(left: 16),
child: Icon(
Icons.delete,
color: Colors.white,
),
alignment: Alignment.centerLeft,
),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)),
color: Colors.white70,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
width: 120,
padding: EdgeInsets.all(10.0),
child: Text(
"Project ",
style: TextStyle(
fontSize: 11, fontWeight: FontWeight.bold),
),
),
Container(
padding: EdgeInsets.all(10.0),
child: ProjectName(),
),
],
),

// item add start

Container(
padding: EdgeInsets.all(10.0),
child: TextFormField(
decoration: InputDecoration(
hintText: "Item name" ,hintStyle: TextStyle(fontSize: 12),
),
),
),
Container(
padding: EdgeInsets.all(10.0),
child: TextFormField(
decoration: InputDecoration(
hintText: "Amount",hintStyle: TextStyle(fontSize: 12),

),
keyboardType: TextInputType.number,
),
),
],
),
),
);
}
),

最佳答案

我想这是您要寻找的东西。只需将ListTile替换为您自己的Card

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomeScreen(),
);
}
}

class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
var listLength = 1;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Flutter App :)"),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
setState(() {
listLength++;
});
}),
body: Container(
child: ListView.builder(
itemCount: listLength,
itemBuilder: (context, index) {
return ListTile(
leading: Text("$index"),
title: Text("List Tile as Widget"),
);
})),
);
}
}

关于flutter - 我想在我的flutter应用程序中通过onPressed方法生成卡。谁能给我看一个路线图…?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64522707/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com