我在 AlertDialog 容器中有一個 ListView。有一種 InkWell 方法,但漣漪效應不起作用,我無法放置分隔符。如何放置分隔符并產生漣漪效應?
Widget setupAlertDialoadContainer(context) {
return Container(
color: Colors.white,
height: 300.0,
width: 300.0,
child: ListView.builder(
itemCount: showroomModel.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
onTap: () => {
print(showroomModel[index]),
},
child: ListTile(
title: Text(showroomModel[index]),
),
);
}),
);
}
uj5u.com熱心網友回復:
用于分離器和波紋效果
ListView.separated(
itemCount: 25,
separatorBuilder: (BuildContext context, int index) => Divider(height: 1),
itemBuilder: (BuildContext context, int index) {
return Inkwell(child:
ListTile(
title: Text('item $index'),
));
},
);
uj5u.com熱心網友回復:
對于InkWell漣漪效應,請嘗試將 包裝InkWell在Material小部件中。
Material(
child: InkWell(
onTap: () {
print(showroomModel[index]);
},
child: ListTile(
title: Text(showroomModel[index]),
),
),
)
對于分隔符ListView.separated,請按照 Tasnuva oshin 的回答使用。
uj5u.com熱心網友回復:
看一下這個 :
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('List app'),
),
body: Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Image Required"),
content: Container(
height: 200,
width: 200,
child: ListView.separated(
itemBuilder: (context, index) {
return Ink(
color: Colors.white,
child: ListTile(
leading: Text("Sample"),
title: Text("title"),
onTap: () {},
),
);
},
separatorBuilder: (context, index) {
return Divider();
},
itemCount: 4,
),
),
actions: <Widget>[
FlatButton(
child: Text("Close"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
},
child: Text('Press'),
),
),
));
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/390017.html
