Search code examples
flutterdartflutter-web

Stack not scrolling if hovering text Flutter


I almost got what I want the page to be like. But the page won't scroll while I am hovering the text on the static column. Is there a workaround to this? Can someone point me to in the right direction?

dart pad

import 'package:flutter/material.dart';

const Color darkBlue = Color.fromARGB(255, 18, 32, 47);

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
      ),
      debugShowCheckedModeBanner: false,
      home: const Scaffold(
        body: Center(
          child: CucinaGardaView(),
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        //
        SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              PhotoItem(
                'https://images.unsplash.com/photo-1601628828688-632f38a5a7d0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1009&q=80',
              ),
              PhotoItem(
                'https://images.unsplash.com/photo-1554995207-c18c203602cb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80',
              ),
              PhotoItem(
                'https://images.unsplash.com/photo-1600210492493-0946911123ea?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1074&q=80',
              ),
            ],
          ),
        ),
//
        Positioned(
          left: MediaQuery.of(context).size.width / 2,
          top: 0.0,
          child: SizedBox(
            width: (MediaQuery.of(context).size.width / 2),
            height: MediaQuery.of(context).size.height,
            child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 100.0),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const Text(
                    'Hello World!',
                    style: TextStyle(fontSize: 50.0),
                  ),
                  RichText(
                    text: const TextSpan(
                      children: [
                        TextSpan(text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."),
                      ],
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ],
    );
  }
}

class PhotoItem extends StatelessWidget {
  PhotoItem(
    this.photoPath, {
    Key? key,
  }) : super(key: key);

  final String photoPath;

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        SizedBox(
          width: MediaQuery.of(context).size.width / 2,
          child: Image.network(
            photoPath,
            fit: BoxFit.cover,
          ),
        ),
        SizedBox(width: MediaQuery.of(context).size.width / 2),
      ],
    );
  }
}

This is just some filler text because stack overflow says that there is too much code in this post...


Solution

  • just wrap your Text inside an IgnorePointer Widget.