简体   繁体   English

flutter中如何将Listview的颜色改为透明?

[英]How to change the color of Listview to transparent in flutter?

Basically i'm making an app which requires the background to have a gradient and now i need the listview to be transparent to have the color show, how am i supposed to do that cause Colors.transparent doesn't work基本上我正在制作一个需要背景具有渐变的应用程序,现在我需要列表视图是透明的才能显示颜色,我应该怎么做,因为 Colors.transparent 不起作用

if your wanna create gradient BG in flutter I Think this would be work如果你想在 flutter 中创建渐变 BG,我认为这可行

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return const MaterialApp(
  // Remove the debug banner
  debugShowCheckedModeBanner: false,
  title: 'Kindacode.com',
  home: HomePage(),
);
}
}

class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
  decoration: const BoxDecoration(
      gradient: LinearGradient(
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          colors: [Colors.purple, Colors.orange])),
  child: Scaffold(
      // By defaut, Scaffold background is white
      // Set its value to transparent
      backgroundColor: Colors.transparent,
      appBar: AppBar(
        backgroundColor: Colors.black45,
        title: const Text('Kindacode.com'),
      ),
      body: Center(
        child: Container(
          width: 200,
          height: 200,
          color: Colors.white,
        ),
      )),
  );
 }
 }

try this code it's work with me to keep the background listview in transparent试试这段代码,它与我一起工作,使背景列表视图保持透明

ListView.builder(
       itemCount: ItemCount,
       itemBuilder: (context, index) {
     return Card(
     color: Colors.transparent,// this line for keep the listview transparent
       child : Row(
           children [
         //your code ])
             
            ),
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM