Bill Rei
Bill Rei

Reputation: 451

Flutter: How to remove empty space at the top of ListView?

I've created a ListView without any padding or margin. But the ListView was separated with empty space like this one:

enter image description here

And this is my code of this ListView:

content: Container(
  width: context.widthPct(.5),
  height: context.heightPct(.4),
  child: CupertinoScrollbar(
    child: ListView(
      children: [
        Center(
          child: Image.asset("assets/logo_horizontal.png"),
        ),
        Align(
          alignment: Alignment.topCenter,
          child: Text(
            "Sumber data doa :\nApa Doanya app\n\nTerima kasih sudah\nmenggunakan Moodo :D\n\nšŸ˜Ž nabilrei šŸ˜Ž\nšŸ˜„ hantsnm šŸ˜„\nšŸ˜‡ rennyatikas šŸ˜‡\nšŸ§ cayne.dameron šŸ§\n",
            style: Style().body,
            textAlign: TextAlign.center,
          ),
        ),
        Center(
          child: Text(
            "versi 1.0.0",
            style: Style(styleColor: Colors.grey.shade600).body,
          ),
        ),
      ],
    ),
  ),
),

So, how can I remove empty space at the top of this ListView?

Upvotes: 13

Views: 12911

Answers (5)

Paras Palli
Paras Palli

Reputation: 201

ListView.builder(
        padding: EdgeInsets.zero,
        itemCount: 30,
        itemBuilder: (context, index) {
          return Text(
            'Job Type',
          );
        },
),

Upvotes: 3

Pranjal kumar_37
Pranjal kumar_37

Reputation: 11

MediaQuery.removePadding( context: context, removeTop: true, child: ListView

It will work for builder also

Upvotes: 0

iamevansobeng
iamevansobeng

Reputation: 545

Set padding to zero

ListView(
   padding: const EdgeInsets.zero,
   itemBuilder: ...,
   itemCount: ...
);

Or control padding in listview

ListView(
  padding: const EdgeInsets.only(top: 20),
  itemBuilder: ...,
  itemCount: ...
);

Upvotes: 3

balu k
balu k

Reputation: 5098

Listview has default padding, you can change it by specifying your required EdgeInsets. To remove padding use EdgeInsets.zero

ListView(
padding: EdgeInsets.zero,
children: [],
);

Upvotes: 36

Jim
Jim

Reputation: 7601

Try

MediaQuery.removePadding(
        context: context,
        removeTop: true,
        child: ListView

Upvotes: 27

Related Questions