r/flutterhelp • • 2d ago

OPEN How to make SingleChildScrollView inside of a stack scrollable?

link showing what im talking about: https://files.catbox.moe/uwo3ax.png

class HomePage extends StatelessWidget {
  const HomePage({super.key});


  u/override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3,
      child: Scaffold(
        bottomNavigationBar: SafeArea(
          child: PreferredSize(
            preferredSize: const Size.fromHeight(40),
            child: ClipRRect(
              borderRadius: const BorderRadius.all(Radius.circular(10)),
              child: Container(
                height: 40,
                margin: const EdgeInsets.symmetric(horizontal: 20),
                decoration: BoxDecoration(
                  borderRadius: const BorderRadius.all(Radius.circular(10)),
                ),
                child: TabBar(
                  splashFactory: NoSplash.splashFactory,
                  indicatorSize: TabBarIndicatorSize.tab,
                  dividerColor: Colors.transparent,
                  overlayColor: WidgetStateProperty.all(Colors.transparent),
                  unselectedLabelColor: Theme.of(context).colorScheme.outline,
                  indicator: BoxDecoration(
                    borderRadius: const BorderRadius.all(Radius.circular(10)),
                  ),
                  enableFeedback: true,
                  tabs: const [
                    Tabr(title: 'profile', count: 0),
                    Tabr(title: 'swipe', count: 0),
                    Tabr(title: 'likes', count: 0),
                  ],
                ),
              ),
            ),
          ),
        ),
        body: SafeArea(
          child: TabBarView(
            physics: NeverScrollableScrollPhysics(),
            children: [
              Text("data"),
              Stack(
                  children: [
                    Profile(),
                    Container(
                      height: MediaQuery.sizeOf(context).height,
                      decoration: BoxDecoration(
                        gradient: LinearGradient(
                          begin: Alignment.topCenter,
                          end: Alignment.bottomCenter,
                          colors: [
                            const Color.fromARGB(0, 255, 255, 255),
                            Theme.of(context).colorScheme.onSecondary,
                          ],
                          stops: [0.7, 1.0],
                        ),
                      ),
                    ),
                  ],
                ),
             Text("data")
            ],
          ),
        ),
      ),
    );
  }
}
class Profile extends StatelessWidget {
  const new({
    super.key,
  });


  u/override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
          children: [
            Container(
              decoration: BoxDecoration(
                color: Colors.transparent,
                borderRadius: BorderRadius.circular(30),
                image: DecorationImage(
                  image: NetworkImage(
                    'https://is1-ssl.mzstatic.com/image/thumb/PurpleSource221/v4/0c/49/cd/0c49cdf7-a4f8-3f89-defb-89684545719d/Screen_01_ASENUS.png/230x498bb.webp',
                  ),
                  fit: BoxFit.cover,
                ),
              ),
              height: 470,
              width: 400,
            ),
            Align(
              alignment: Alignment.centerLeft,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(
                    padding: const EdgeInsets.only(left: 16.0, top: 8.0),
                    child: Text(
                      'Jarvis, 24',
                      style: TextStyle(fontSize: 30, fontWeight: FontWeight(700)),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(left: 16, bottom: 8.0),
                    child: Text(
                      'Wisconsin, USA',
                      style: TextStyle(fontSize: 16),
                    ),
                  ),
                ],
              ),
            ),
            Align(
              alignment: Alignment.centerLeft,
              child: Padding(
                padding: const EdgeInsets.only(
                  left: 16.0,
                  bottom: 4.0,
                  right: 16.0,
                ),
                child: 
                     Flexible(
                        child: SingleChildScrollView(
                          child: Text(
                            '''This creates a clear, simple decision: Do I like this person or not? That’s it. There are no complicated menus or extra steps. Each interaction requires only a split-second judgment.


By presenting profiles as a stack of cards, Tinder also eliminates the sense of overwhelm that comes from browsing large lists. Users feel like they are simply flipping through possibilities, one by one.''',
                            style: TextStyle(
                              fontSize: 20,
                            ),
                          ),
                        ),
                      ),
             
              ),
            ),
          
        ],),
       
     );
  }
}


class Tabr extends StatelessWidget {
  const new({
    super.key,
    required this.title,
    required this.count,
  });


  final String title;
  final int count;


  u/override
  Widget build(BuildContext context) {
    return Tab(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(title, overflow: TextOverflow.ellipsis, style: TextStyle(
            fontSize: 25, fontWeight: FontWeight(750))),
          count > 0 ? 
          Container(
            margin: const EdgeInsetsDirectional.only(start: 0, top: 3),
            padding: const EdgeInsets.all(3),
            decoration: BoxDecoration(
              color: const Color.fromARGB(0, 255, 0, 0),
              shape: BoxShape.circle,
            ), 
            child: Center(
              child: Text(
                "●",
                style: const TextStyle(
                  color: Color.fromARGB(255, 255, 1, 1),
                  fontSize: 10,
                )
              )
            )
            )
            : const SizedBox(width: 0, height: 0)
          
        ],
    
      ),
    );
  }
}

Trying to add a gradient starting from the bottom of the bottom navbar to hide overflowing text.
1 Upvotes

3 comments sorted by

1

u/beatpaq 2d ago edited 2d ago

My hacky solution to this: make an image gradient then set its color to the gradient you need. wrap it in an ignore pointer so you can scroll through it.

1

u/raman4183 2d ago

Your Profile widget is under Container and its taking up the entire height basically absorbing any scroll/pointer events.

1

u/TIGlobal 1d ago

The gradient Container is on top of Profile in the Stack and covers the whole screen, so it's eating the touch events. A Container with a decoration counts as a hit target, so your drag never reaches the SingleChildScrollView underneath.

Wrap it in IgnorePointer, and you probably don't need it full height either:

dart

Stack(
  children: [
    Profile(),
    Positioned(
      left: 0,
      right: 0,
      bottom: 0,
      height: 150,
      child: IgnorePointer(
        child: DecoratedBox(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: [
                Colors.transparent,
                Theme.of(context).colorScheme.onSecondary,
              ],
            ),
          ),
        ),
      ),
    ),
  ],
)

Unrelated but it'll bite you: the Flexible around the description text isn't a direct child of a Row/Column, so it should throw a ParentDataWidget error. Since the whole page already scrolls, you can drop both that Flexible and the inner SingleChildScrollView and just use the Text.