Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter ListView not scrolling (I feel like I've tried every solution on the internet)

If I drag and hold my finger down I can see a few items that are below the cutoff of the screen but as soon as I let go, it just bounces back to the top. I tried using SingleChildScrollView places, tried setting primary = true, and a bunch of other stuff that didn't help. I'm fairly new to flutter so any help would be appreciated!! Let me know if any more info is needed.

Here is my code:

import 'package:flutter/material.dart';
import 'package:drink_specials/models/restaurant.dart';
import 'package:drink_specials/screens/home/restaurant_list.dart';

class RestaurantNameTextStyle {
  static TextStyle display5(BuildContext context) {
    return Theme.of(context).textTheme.headline2.copyWith(color: Colors.white);
  }
}

class RestaurantTypeTextStyle {
  static TextStyle display5(BuildContext context) {
    return Theme.of(context).textTheme.headline6.copyWith(color: Colors.white);
  }
}


class RestaurantDetail extends StatelessWidget {

  final Restaurant restaurant;
  RestaurantDetail({Key key, @required this.restaurant}) : super(key: key);

  @override
  Widget build(BuildContext context) {

    final topContentText = Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        SizedBox(height: 100.0),
        Text(
          restaurant.name,
          style: RestaurantNameTextStyle.display5(context),
        ),
        SizedBox(height: 10.0),
        Expanded(
            flex: 6,
            child: Padding(
                padding: EdgeInsets.only(left: 10.0),
                child: Text(
                  restaurant.restaurant_type,
                  style: RestaurantTypeTextStyle.display5(context),
                ))),
      ],
    );

    final topContent = Stack(
      children: <Widget>[
        Container(
            padding: EdgeInsets.only(left: 10.0),
            height: MediaQuery.of(context).size.height * 0.5,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: NetworkImage(restaurant.photo),
                fit: BoxFit.cover,
              ),
            )),
        Container(
          height: MediaQuery.of(context).size.height * 0.5,
          padding: EdgeInsets.all(40.0),
          width: MediaQuery.of(context).size.width,
          decoration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, .9)),
          child: Center(
            child: topContentText,
          ),
        ),
        Positioned(
          left: 8.0,
          top: 60.0,
          child: InkWell(
            onTap: () {
              Navigator.pop(context);
            },
            child: Icon(Icons.arrow_back, color: Colors.white),
          ),
        )
      ],
    );


    final bottomContent = Container(
      width: MediaQuery.of(context).size.width,
      padding: EdgeInsets.all(8.0),
      child: Center(
        child: ListView.builder(
          scrollDirection: Axis.vertical,
          physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
          itemCount: restaurant.specials.length,
          itemBuilder: (context, index) {
            final item = restaurant.specials[index];
            return Card(
              elevation: 8.0,
              margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
              child: Container(
                decoration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, 1.0)),
                child: ListTile(
                  contentPadding: EdgeInsets.symmetric(horizontal:20, vertical:10),
                  title: Text(item, style: TextStyle(color: Colors.white)),
            )
                ),
            );
          }
        ),
      ),
    );

    return Scaffold(
      body: Column(
        children: <Widget>[
          topContent,
          Expanded(
            child: bottomContent,
          ),
        ],
      ),
    );
  }
}

like image 604
Storm D. Avatar asked Dec 02 '25 06:12

Storm D.


2 Answers

There is a ListView inside a SingleChildScrollView and both of them are scrollable. Scrolling on one of them should be disabled.

like image 114
Ehsan Askari Avatar answered Dec 03 '25 22:12

Ehsan Askari


ListView already have scroll behavior so you won't need some SingleChildScrollView

like image 31
Dwi Kurnianto M Avatar answered Dec 03 '25 22:12

Dwi Kurnianto M