Created
December 27, 2023 09:10
-
-
Save DaisukeNagata/d5f50193bacc36c229e87951e57f83d9 to your computer and use it in GitHub Desktop.
Bubbling sample by Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
const MyHomePage({Key? key}) : super(key: key); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
String tex = 'child'; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Bubbling sample'), | |
), | |
body: NotificationListener<ScrollNotification>( | |
onNotification: (ScrollNotification notification) { | |
setState(() { | |
tex = 'parent'; | |
}); | |
return true; | |
}, | |
child: SizedBox( | |
width: MediaQuery.of(context).size.width, | |
child: ChildWidget( | |
tex: tex, | |
), | |
), | |
), | |
); | |
} | |
} | |
class ChildWidget extends StatelessWidget { | |
const ChildWidget({super.key, required this.tex}); | |
final String tex; | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
height: 150, // コンテナの高さ | |
color: Colors.grey[200], | |
margin: const EdgeInsets.all(8.0), | |
child: NotificationListener<ScrollNotification>( | |
onNotification: (ScrollNotification notification) { | |
return false; // false is propagate the notification | |
}, | |
child: SingleChildScrollView( | |
child: Column( | |
children: List.generate( | |
20, | |
(itemIndex) => Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Text('Bubbling $tex'), | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
default.mov