html editor enhanced alert dialog not working when the dialog placed on editor - flutter

Dependency : html_editor_enhanced: ^2.4.0+1
HtmlEditor(
controller: controller,
htmlEditorOptions: HtmlEditorOptions(
darkMode: true,
initialText: _phase!.value,
hint: "Enter you information",
autoAdjustHeight: false,
shouldEnsureVisible: true,
webInitialScripts:
UnmodifiableListView([
WebScript(
name: "editorBG",
script:"document.getElementsByClassName('note-editable')[0].style.backgroundColor='blue';"),
WebScript(
name: "height",
script: """
var height = document.body.scrollHeight;
window.parent.postMessage(JSON.stringify({"type": "toDart: height", "height": height}), "*"); //,"color":'white'
"""),
]
)
),
htmlToolbarOptions:
const HtmlToolbarOptions(
// toolbarItemHeight: 90.0,
// gridViewHorizontalSpacing: 0.1,
// gridViewVerticalSpacing: 0.1,
toolbarPosition: ToolbarPosition.aboveEditor,
toolbarType: ToolbarType.nativeGrid
),
otherOptions: OtherOptions(
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.circular(10.0),
border: Border.all(
color: const Color.fromRGBO(244, 248, 248, 1),
width: 2),
),
),
);
If I click alert dialog(image choose) cancel or ok button, then click goes to editor only which is placed under dialog box. please confirm what other dependency is compatible for this... also this is flutter inbuild widget which they already wrap it with PointerInterceptor... but still it is not working

Problem:
html_editor_enhanced uses an HtmlElementView to display the editor and the HtmlElementView consume mouse events before Flutter gets to consume the events.
When overlaying Flutter widgets on top of HtmlElementView widgets that
respond to mouse gestures (handle clicks, for example), the clicks
will be consumed by the HtmlElementView, and not relayed to Flutter.
The result is that Flutter widget's onTap (and other) handlers won't
fire as expected, but they'll affect the underlying webview.
Source: pointer_interceptor docs
Solution:
Wrap the dialog widget with a PointerInterceptor from the pointer_interceptor package.
From the docs:
PointerInterceptor is a widget that prevents mouse events (in web)
from being captured by an underlying HtmlElementView.
So if your dialog code was this previously:
AlertDialog(
content: Container(
...
)
)
You should update it to this:
PointerInterceptor(
AlertDialog(
content: Container(
...
)
)
)

I've been having a similar issue, but I found this https://github.com/flutter/flutter/issues/54027#issuecomment-797757996
Try running your flutter app with "--web-renderer html".

if you face an error after ok or cancel you should clear focus before the dialog/page closed use the below function, first create a controller for the htmleditor
editorController.clearFocus();

Related

How can i add some space between two buttons (Flutter fire ui)

How can i add space between sign in button and sign in with google, please not that its is flutter fire ui, i just use bellow built in functions which automatically implement the ui.
providerConfigs: const [
EmailProviderConfiguration(),
GoogleProviderConfiguration(
clientId: '316263778394:android:7ce6031f0d41db0503b063',
),
PhoneProviderConfiguration(),
],
From your code it looks like providerConfigs takes List<Widget> as argument and arranges the Widgets vertically.
If that's true then you can just add SizedBox(height: <desired height>, width: 1) in-between the two elements you want to add space.
I believe the below code should work:
providerConfigs: const [
EmailProviderConfiguration(),
GoogleProviderConfiguration( clientId: '316263778394:android:7ce6031f0d41db0503b063', ),
SizedBox(height: 20, width: 1),
PhoneProviderConfiguration(),
],
You can add a const declaration for the SizedBox.

Is there a way for the showTimePicker() in Flutter to not reset any value in TextInputField?

I implemented a page in my Flutter application that has a text input field and 2 time pickers that are activated by pressing the button to make them appear. The issue is that if I have a new value in the TextInputField and use one of the time pickers, after I'm done what I have typed in the input field will just reset.
Code snippet from the input field:
SizedBox(
width: 350,
child: TextField(
controller: titleController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
hintText: 'Title',
),
onChanged: (value) {
title = value;
},
),
),
I've tried keeping the value of what is being typed in through a titleController and I have also attempted using the onChanged() method and a separate variable to keep the value in there. These solutions both didn't work for me, however. Is there any other solution to this issue?
If your TextField inside a stateless widget it will keep clearing the value of the controller everytime something pop on the screen, so try to put your TextField inside a stateful widget

How to show multiple GetX snackbars at once

I want to popup multiple snackbars like they are on top of eachother.
Is there a way to do that ?
Get.snackbar(
"test",
"test",
backgroundColor: secondaryColor,
maxWidth: 350,
margin: EdgeInsets.only(left: Get.height * 0.95),
isDismissible: false,
)
You can not show popup as stack.. with Get.snackbar because the Concept of Get is a Context less Widget tree. and for dialogue popup with Get each dialogue is created separated and show one and after such as ques FIFO.. for that approaches you need to think out side the Get then you will get your desire result
Happy Coding.... :)

How to detect new position of video in Flutter?

So I am using the video_player package in my Flutter project and have made use of VideoProgressIndicator and it works exactly as intended:
Widget progBar(BuildContext context) {
return VideoProgressIndicator(
_controller,
allowScrubbing: true, // user can touch/drag bar to change position of video.
colors: VideoProgressColors(playedColor: Colors.red, bufferedColor: Colors.white),
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 9),
);
}
The issue:
I have the timestamp(s) of the video as part of the player and when the user uses the VideoProgressIndicator to change the position of the video, I don't have the new position of the video so that I can update the timestamp(s).
My question:
How can I get the new position of the video when the VideoProgressIndicator changes it?
Thank You!
Ok so I figured out my solution to be simply to create a custom progress bar that manipulates a timer.

Best way to allow a bit of overscroll in a CustomScrollView

The UI I'm making usually starts with the bottom sliver scrolled all the way in, so that its top is at the top of the view. But also:
Needs an extra empty space at the top, in case the user wants to pull the content down so that they can reach it without moving their hand from the bottom of the phone (this is a really basic ergonomic feature and I think we should expect to see it become pretty common soon, first led by apps moving more of their key functionality to the bottom of the screen, EG, Firefox's url bar.) (Currently, I'm using the appBar sliver for this, but I can imagine a full solution not using that)
Might need extra empty space at the bottom, whenever the content in that bottom sliver wont be long enough to allow it to be scrolled in all the way. It will seem buggy and irregular otherwise. Ideally I'd impose a minHeight so that the bottom sliver will always at least as tall as the screen, but it's a sliver, so I'm pretty sure that's not possible/ugly-difficult.
The avenue I'm considering right now is, ScrollPhysics wrapper that modifies its ScrollMetrics so that maxExtent and minExtent are larger. As far as I can tell, this will allow the CustomScrollView (given this ScrollPhysics) to overscroll. It feels kinda messy though. It would be nice to know what determines maxExtent and minExtent in the first place and alter that.
Lacking better options, I went ahead with the plan, and made my own custom ScrollPhysics class that allows overscroll by the given amount, extra.
return CustomScrollView(
physics: _ExtraScrollPhysics(extra: 100 * MediaQuery.of(context).devicePixelRatio),
...
And _ExtraScrollPhysics is basically just an extended AlwaysScrollable with all of the methods that take ScrollMetrics overloaded to copy its contents into a ScrollMetric with a minScrollExtent that has been decreased by -extra, then passing it along to the superclass's version of the method. It turns out that adjusting the maxScrollExtent field wasn't necessary for the usecase I described!
This has one drawback, the overscroll glow indicator, on top, appears at the top of the content, rather than the top of the scroll view, which looks pretty bad. It looks like this might be fixable, but I'd far prefer a method where this wasn't an issue.
mako's solution is a good starting point but it does not work for mouse wheel scrolling, only includes overscroll at the top, and did not implement the solution to the glow indicator problem.
A more general solution
For web, use a Listener to detect PointerSignalEvents, and manually scroll the list with a ScrollController.
For mobile, listening for events is not needed.
Extend a ScrollPhysics class as mako suggested but use NeverScrollableScrollPhysics for web to prevent the physics from interfering with the manual scrolling. To fix the glow indicator problem for mobile, wrap your CustomScrollView in a ScrollConfiguration as provided by nioncode.
Add overscroll_physics.dart from the gist.
Add custom_glowing_overscroll_indicator.dart from the other gist.
GestureBinding.instance.pointerSignalResolver.register is used to prevent the scroll event from propogating up the widget tree.
Example
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:my_project/custom_glowing_overscroll_indicator.dart';
import 'package:my_project/overscroll_physics.dart';
class OverscrollList extends StatelessWidget {
final ScrollController _scrollCtrl = ScrollController();
final double _topOverscroll = 200;
final double _bottomOverscroll = 200;
void _scrollList(Offset offset) {
_scrollCtrl.jumpTo(
_scrollCtrl.offset + offset.dy,
);
}
#override
Widget build(BuildContext context) {
return Container(
height: 300,
decoration: BoxDecoration(border: Border.all(width: 1)),
child: Listener(
onPointerSignal: (PointerSignalEvent event) {
if (kIsWeb) {
GestureBinding.instance.pointerSignalResolver.register(event, (event) {
_scrollList((event as PointerScrollEvent).scrollDelta);
});
}
},
child: ScrollConfiguration(
behavior: OffsetOverscrollBehavior(
leadingPaintOffset: -_topOverscroll,
trailingPaintOffset: -_bottomOverscroll,
),
child: CustomScrollView(
controller: _scrollCtrl,
physics: kIsWeb
? NeverScrollableOverscrollPhysics(
overscrollStart: _topOverscroll,
overscrollEnd: _bottomOverscroll,
)
: AlwaysScrollableOverscrollPhysics(
overscrollStart: _topOverscroll,
overscrollEnd: _bottomOverscroll,
),
slivers: [
SliverToBoxAdapter(
child: Container(width: 400, height: 100, color: Colors.blue),
),
SliverToBoxAdapter(
child: Container(width: 400, height: 100, color: Colors.yellow),
),
SliverToBoxAdapter(
child: Container(width: 400, height: 100, color: Colors.red),
),
SliverToBoxAdapter(
child: Container(width: 400, height: 100, color: Colors.orange),
),
],
),
),
),
);
}
}
dartpad demo
Mobile result: