How to ignore enter button on keyboard for flutter web? - flutter

For flutter web, pressing enter triggers an event. How can I ignore the use case where the user presses the enter key on their keyboard

Did you try this way?
import 'package:flutter/services.dart';
MaterialApp(
shortcuts: Map.of(WidgetsApp.defaultShortcuts)
..remove(LogicalKeySet(LogicalKeyboardKey.enter)), //<-- add this to materialapp
...
)
to ignore keyboard on widget i had many search and i found a solution, but im not sure about it:
you can use ShortcutManager
Shortcuts.manager(
manager: ShortcutManager(
shortcuts: Map.of(WidgetsApp.defaultShortcuts)
..remove(LogicalKeySet(LogicalKeyboardKey.enter))
..remove(LogicalKeySet(LogicalKeyboardKey.numpadEnter)),
),
child: TextField(),
),
i hope this works

Related

Flutter Global Keyboard Shortcuts

I am writing an application that should support searching some content. For this I implemented a search TextField. Now I would like to focus said TextField when the key combination ctrl + F is pressed.
In order to implement this, I wrapped my view in both a Shortcuts and Actions component as follows:
return Scaffold(
body: Shortcuts(
shortcuts: {
LogicalKeySet(LogicalKeyboardKey.keyF, LogicalKeyboardKey.control): MTCSearchIntent(),
},
child: Actions(
actions: {
MTCSearchIntent: MTCFocusAction(null),
},
child: ...
),
),
);
This implementation works if the search bar is already focused, but that kind of defeats the purpose of focusing it.. So I was wondering, how can I apply the Shortcut listener to the entire screen? Or asked differently, what determines the scope of the interactions, the Shortcut component, the Action component, something related to the FocusNode?
The example on flutter.dev don't seem to work globally either. In fact they don't seem to work at all for me.
I reproduced the example using a minimal example here: https://dartpad.dev/?id=55902a179be137d9025ea02170d749a7
When the TextField is focused, the ArrowUpand ArrowDown actions work as intended. However, if any other part of the application is highlighted, the Intent is never triggered.

How to disable Bold Text set by iOS Accessibility setting in Flutter?

I know I should not disable any of the text and bold settings set on the device but I have a reason for it. I have disabled the text size by setting the textScaleFactor to 1 on a global level. But this does nothing to avoid the user from setting the Bold Text option that also changes the size of the text. How do I override that function also so even if the user sets it on the device there is no effect on the app? I have tried setting the fontweitgh on the text item using a TextStyle but that does also not stop the Bolding.
After checking Text widget I found out that it's using boldTextOverride from MediaQuery to change font weight of default text style provided to it. So I guess you can override it by wrapping your MeterialApp inside of a MediaQuery and assigning false to boldText and set useInheritedMediaQuery on MaterialApp to true to prevent it from creating another MediaQuery. Something like this:
return MediaQuery(
data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window).copyWith(boldText: false),
child: MaterialApp(
useInheritedMediaQuery: true,
),
);
Amir_P's answer is good but, when testing it out, I found that it breaks switching between dark mode and light mode in system, as the Flutter app would only apply system brightness after killing and reopening the app on iOS rather than immediately while the app is open. Therefore, I think that rather than wrapping MaterialApp in a MediaQuery, the following should be done:
return MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(boldText: false),
child: child!,
),
);
The builder property of the Material App is specifically for overriding things like this - see https://api.flutter.dev/flutter/material/MaterialApp/builder.html

Flutter web update url/route base on state

I'm new in flutter and I just want to know if this scenario/feature is possible in flutter/flutter web. I want to update the url/route base on the state of the screen. For example, in 9gag.com, there are buttons for Hot, Trending, and Fresh. Then, if I clicked the Hot button its url will be updated to 9gag.com/hot and also its contents, the same goes for Trending and Fresh buttons. Is this possible in flutter/flutter web? If so, how do I implement this feature?(much better if the implementation uses bloc)
Totally possible and is very easy to achieve just use url_launcher Package on onpressed/ontap
Example: Add this code somewhere like in the beginning of your stateful management or at the end of your code
_launchURL() async {
const url = 'https://flutter.io';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Call it somewhere like this
RaisedButton(
onPressed: _launchURL,
child: new Text('Show Flutter homepage'),
),
),
Now if you have some 9gag/hot button or container whatever you are going with just put that url and when user taps it, it will open that url. If you want to open it inside the app webview that's also possible but slightly different.
If I understood correctly It's pretty straightforward use the default way of navigation and routing.
I'm not sure with your approach like you have mentioned
I want to update the url/route base on the state of the screen
and
Then, if I clicked the Hot button its url will be updated to 9gag.com/hot and also its contents
If I'm not wrong there is a inbuilt feature of navigating to other screens and once you land on the desired screen, you can see the refreshed content. If you want to try material design the code will be like this
//within your stateful or stateless widget
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => YourPage()),
Instead of using a package you can try this inbuilt way of doing the same job. But it's upto you which one you want to use. Checkout the official flutter documentation https://flutter.dev/docs/cookbook/navigation
I hope this approach also helps to answer your question. If so happy to help in your flutter journey, if not share that how did you solved it.

Flutter Image Hovering Overlay Effect

I am working on a flutter web project and I want to the following overlay effect over my image that whenever the cursor hovers over the image, a few buttons should show up, and the opacity of the image gets reduced (or blurred out) while hovering.
I have tried InkWell and GestureDectector but nothing seems to work.
This is basically what I am trying to achieve : Preview.
Try using hovering package to achieve the hovering effect on flutter_web.
First, import the package:
import 'package:hovering/hovering.dart';
Add a GlobalKey within your StatelessWidget:
final _key = GlobalKey<ScaffoldState>();
And then, use the HoverWidget:
HoverWidget(
hoverChild: Container(
height: 200,
width: 200,
color: Colors.green,
child: Center(child: Text('Hover Me..')),
),
onHover: (event) {
_key.currentState.showSnackBar(SnackBar(
content: Text('Yaay! I am Hovered'),
));
},
child: Container(
height: 200,
width: 200,
color: Colors.red,
child: Center(child: Text('Hover Me..')),
),
)
Check the example use case here
Hi Raj this is pretty simple
You just need to use Listener Widget which detects onPointerHover and update you app's state
Here is the api link follow it
Listener in Flutter
If any difficulties comment down below
Okay, over time I have tried many ways and would like to share my insight in case somebody else is looking for the same solution too.
So, the basic way to achieve this is to use the Hovering package.
Another way would be to use MouseRegion.
You can use the onEnter and onExit property of MouseRegion to detect when did the cursor entered and left the region/container you are trying to add a hove effect to.
You can use that to switch between your different app states.
Or it has onHover property as well, that basically tells that if the cursor is currently hovering that region or not you can use that too.
Note: I tried the Listener widget as well, but either I didn't understood it well, or it was too complicated to work with. Anyways, I couldn't achieve what I wanted.

In Flutter, How does one create a 'how this app works' walk-through?

I want to launch a simple walk-through for our app. The user would log in for the first time (or select the 'tutorial' option in settings), and it would walk you through how to use the app.
To clarify, the app would launch a dialog/alertdialog and the background would go grey or become greyed out highlighting specific areas/buttons of the app to talk them through it. The dialog box would have a child of Text explaining how to use it.
After the user has clicked through the steps the tutorial would end but could be reactivated in settings.
Any help would be appreciated.
Thanks
There is a plugin called showcaseview and does pretty much what you want. You can get it here. For using it you need to wrap the page you want to show in a ShowCaseWidget
ShowCaseWidget(
builder: Builder(
builder : (context) () => Somewidget()
),
),
then for every part of the page you want to show a guide for it, wrap it in a ShowCase
Showcase(
key: _one,
title: 'Menu',
description: 'Click here to see menu options',
child: Icon(
Icons.menu,
color: Colors.black45,
),
),