Home > Software engineering >  How to change the color of Listview to transparent in flutter?
How to change the color of Listview to transparent in flutter?

Time:04-28

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

CodePudding user response:

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 ])
             
            ),
})

CodePudding user response:

if your wanna create gradient BG in flutter I Think this would be work

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,
        ),
      )),
  );
 }
 }
  • Related