Guest User

Untitled

a guest
Apr 29th, 2023
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. It sounds like you are having an issue with scrolling in a Flutter PWA (Progressive Web App) for the Telegram Web App. To fix the issue where the scroll affects the popup and the background content at the same time, you can try the following solution:
  2.  
  3. Disable scrolling on the main content when the popup is open.
  4. You can achieve this by wrapping your main content inside a GestureDetector and setting its onVerticalDragDown and onVerticalDragUpdate callbacks to empty functions when the popup is open.
  5.  
  6. Here's a code snippet to help you with this:
  7.  
  8. dart
  9. Copy code
  10. import 'package:flutter/material.dart';
  11.  
  12. void main() {
  13. runApp(MyApp());
  14. }
  15.  
  16. class MyApp extends StatelessWidget {
  17. @override
  18. Widget build(BuildContext context) {
  19. return MaterialApp(
  20. home: MyHomePage(),
  21. );
  22. }
  23. }
  24.  
  25. class MyHomePage extends StatefulWidget {
  26. @override
  27. _MyHomePageState createState() => _MyHomePageState();
  28. }
  29.  
  30. class _MyHomePageState extends State<MyHomePage> {
  31. bool _isPopupOpen = false;
  32.  
  33. @override
  34. Widget build(BuildContext context) {
  35. return Scaffold(
  36. appBar: AppBar(title: Text('Telegram Web App')),
  37. body: GestureDetector(
  38. onVerticalDragDown: _isPopupOpen ? (details) {} : null,
  39. onVerticalDragUpdate: _isPopupOpen ? (details) {} : null,
  40. child: ListView.builder(
  41. itemCount: 50,
  42. itemBuilder: (context, index) => ListTile(title: Text('Item $index')),
  43. ),
  44. ),
  45. floatingActionButton: FloatingActionButton(
  46. onPressed: () {
  47. setState(() {
  48. _isPopupOpen = !_isPopupOpen;
  49. });
  50. },
  51. child: Icon(Icons.add),
  52. ),
  53. );
  54. }
  55. }
  56. In this example, when you tap the floating action button, it toggles the _isPopupOpen variable, which disables or enables the scrolling on the main content.
  57.  
  58. Make sure your popup is using the Stack or Overlay widget.
  59. To properly show a popup in Flutter, you should use the Stack or Overlay widget. These widgets allow you to overlay content on top of other content without affecting the layout of the main content.
  60.  
  61. Here's an example of how to use a Stack widget to show a popup:
  62.  
  63. dart
  64. Copy code
  65. // Inside the build method of your widget
  66. @override
  67. Widget build(BuildContext context) {
  68. return Scaffold(
  69. appBar: AppBar(title: Text('Telegram Web App')),
  70. body: Stack(
  71. children: [
  72. // Main content (with scrolling disabled when the popup is open)
  73. GestureDetector(
  74. // ...
  75. ),
  76. // Popup
  77. if (_isPopupOpen)
  78. Positioned.fill(
  79. child: GestureDetector(
  80. onTap: () {
  81. setState(() {
  82. _isPopupOpen = false;
  83. });
  84. },
  85. child: Container(
  86. color: Colors.black54,
  87. child: Center(
  88. child: Card(
  89. child: Padding(
  90. padding: EdgeInsets.all(16),
  91. child: Text('Your Popup Content'),
  92. ),
  93. ),
  94. ),
  95. ),
  96. ),
  97. ),
  98. ],
  99. ),
  100. );
  101. }
  102. In this example, the Stack widget is used to place the popup on top of the main content. The Positioned.fill widget ensures that the popup covers the entire screen, and the GestureDetector is used to close the popup when tapping outside it.
  103.  
  104. By combining these solutions, you should be able to fix the scrolling issue in your Flutter PWA for the Telegram Web App.
Advertisement
Add Comment
Please, Sign In to add comment