Comments (4)
Can you please show a screenshot of the full page with the notification showing "Hello World!"? Are you running locally in debug mode with
flutter run -d chrome
, as I am?
Yes, I ran locally with same command. Interestingly, when I for the first time ran the code, I did see the notification on the top right corner of the screen but I didn't take screenshot or video record it and now when I tried again, I don't see it occuring, so I missed the chance to record it : (
I will keep the issue open for team's attention / tracking.
stable, master flutter doctor -v
[!] Flutter (Channel stable, 3.22.2, on macOS 12.2.1 21D62 darwin-x64, locale
en-GB)
• Flutter version 3.22.2 on channel stable at
/Users/dhs/documents/fluttersdk/flutter
! Warning: `flutter` on your path resolves to
/Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
your current Flutter SDK checkout at
/Users/dhs/documents/fluttersdk/flutter. Consider adding
/Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
! Warning: `dart` on your path resolves to
/Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 761747bfc5 (33 hours ago), 2024-06-05 22:15:13 +0200
• Engine revision edd8546116
• Dart version 3.4.3
• DevTools version 2.34.3
• If those were intentional, you can disregard the above warnings; however
it is recommended to use "git" directly to perform update checks and
upgrades.
[!] Xcode - develop for iOS and macOS (Xcode 12.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
! Flutter recommends a minimum Xcode version of 13.
Download the latest version or update via the Mac App Store.
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] VS Code (version 1.62.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.21.0
[✓] Connected device (5 available)
• SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30)
• Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 •
ios • iOS 14.4.1 18D61
• iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 •
ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
• macOS (desktop) • macos •
darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64
• Chrome (web) • chrome •
web-javascript • Google Chrome 98.0.4758.80
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.
[!] Flutter (Channel master, 3.23.0-13.0.pre.262, on macOS 12.2.1 21D62
darwin-x64, locale en-GB)
• Flutter version 3.23.0-13.0.pre.262 on channel master at
/Users/dhs/documents/fluttersdk/flutter
! Warning: `flutter` on your path resolves to
/Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
your current Flutter SDK checkout at
/Users/dhs/documents/fluttersdk/flutter. Consider adding
/Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
! Warning: `dart` on your path resolves to
/Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 6a8f70f11e (2 hours ago), 2024-06-18 00:12:10 -0400
• Engine revision 78fdd06af5
• Dart version 3.5.0 (build 3.5.0-272.0.dev)
• DevTools version 2.36.0
• If those were intentional, you can disregard the above warnings; however
it is recommended to use "git" directly to perform update checks and
upgrades.
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/dhs/Library/Android/sdk
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for
more details.
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 13C100
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 65.1.4
• Dart plugin version 213.7228
[✓] VS Code (version 1.62.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.29.0
[✓] Connected device (3 available)
• Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
• iOS 15.3.1 19D52
• macOS (desktop) • macos •
darwin-x64 • macOS 12.2.1 21D62 darwin-x64
• Chrome (web) • chrome •
web-javascript • Google Chrome 109.0.5414.119
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.
[!] Xcode - develop for iOS and macOS (Xcode 12.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
! Flutter recommends a minimum Xcode version of 13.
Download the latest version or update via the Mac App Store.
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] VS Code (version 1.62.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.21.0
[✓] Connected device (5 available)
• SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30)
• Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 •
ios • iOS 14.4.1 18D61
• iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 •
ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
• macOS (desktop) • macos •
darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64
• Chrome (web) • chrome •
web-javascript • Google Chrome 98.0.4758.80
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.
from flutter.
Notification
from dart:html is not working. Is this code meant to show a notification?
This does work. You need to allow notifications to show, as below:
![Screenshot 2024-06-17 at 4 03 15 PM](https://private-user-images.githubusercontent.com/67046386/340276694-87504b4c-e5f5-4320-a668-471e96956fe2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2NzQ2MDMsIm5iZiI6MTcxOTY3NDMwMywicGF0aCI6Ii82NzA0NjM4Ni8zNDAyNzY2OTQtODc1MDRiNGMtZTVmNS00MzIwLWE2NjgtNDcxZTk2OTU2ZmUyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI5VDE1MTgyM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM3MTU3MTNmMzk4MjYxNmVmOGU3MGZjYzAyMTliMjU0MjU1OTVjNTcyMWU0N2Y0MDFkZWM2MzgwZjQ2Yjk5MzQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.y_dyFB-ESDG-wzswmQaSCr3PkdROg7_IRjkojOoBYGw)
Then upon running the given code, it shows the notifications and gets printed in the console as well:
A Dart VM Service on Chrome is available at: http://127.0.0.1:52353/_CeaKEIrgOQ=
Hello, World!
from flutter.
@darshankawar Thanks. I click "Allow" when that pops up. But then no notification is shown to me.
![Screenshot 2024-06-18 at 7 24 28 AM](https://private-user-images.githubusercontent.com/26356162/340428204-0a27134b-59b7-4a6e-907f-8d4524a9d767.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2NzQ2MDMsIm5iZiI6MTcxOTY3NDMwMywicGF0aCI6Ii8yNjM1NjE2Mi8zNDA0MjgyMDQtMGEyNzEzNGItNTliNy00YTZlLTkwN2YtOGQ0NTI0YTlkNzY3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI5VDE1MTgyM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMxYzlhMGNhMzU0YjM2NjAxNTNkYzFiZWJhNGQ1YzRmYTFiMThjZTQ2ZDJhYTliZjlmNzliYTc1MDUwNzM3YjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.kE6sQ59gjCflDyq-gHchHqV7i5Aq0Ib_e8emog5pkEY)
I'm expecting to also see a new notification every time I click the FAB, but don't:
![Screenshot 2024-06-18 at 7 22 28 AM](https://private-user-images.githubusercontent.com/26356162/340428300-26921b10-f534-46de-9f22-917b065ad48b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2NzQ2MDMsIm5iZiI6MTcxOTY3NDMwMywicGF0aCI6Ii8yNjM1NjE2Mi8zNDA0MjgzMDAtMjY5MjFiMTAtZjUzNC00NmRlLTlmMjItOTE3YjA2NWFkNDhiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI5VDE1MTgyM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc3YmNmNTI3ODU4N2I4YzdiZDMzZjg0OWJkMzdhNmMxM2RkOGNhYzhhYmQ4MWY5Mjk5YTMyMzRiNDMzOTc5YTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.0jg4dLl4uClx7LtSWOnpqAACVz0trWVsM51sZGdfeX8)
Can you please show a screenshot of the full page with the notification showing "Hello World!"? Are you running locally in debug mode with flutter run -d chrome
, as I am?
My version of chrome is Version 125.0.6422.176 (Official Build) (arm64). I just updated to Version 126.0.6478.62 (Official Build) (arm64) but it didn't fix it.
from flutter.
Thanks for creating this issue; dart:html
is a very thin js-interop layer that enables Flutter Web apps use standard JS APIs, in this case, the "Notifications API". Here's its documentation:
Here's some highlights from the documentation that are causing this issue (and its reproduction):
the user needs to grant permission to display notifications, which is generally done when the app or site initializes, using the
Notification.requestPermission()
method. This should be done in response to a user gesture, such as clicking a button.
...
This is not only best practice but going forward browsers will explicitly disallow notifications not triggered in response to a user gesture. 💔
The reproduction code provided is attempting to requestPermission
and display notifications without user interaction (on its initState
method)
Proposed solution
I'd modify the _MyHomePageState
class from the reproduction to something like this:
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
/// onPressed, display a notification and increase the counter.
void _incrementCounter() async {
await displayNotification();
setState(() {
_counter++;
});
}
/// Always request for permissions, and if 'granted', display a notification.
Future<void> displayNotification() async {
final permission = await html.Notification.requestPermission();
if (permission == 'granted') {
html.Notification('About to update counter to: ${_counter + 1}');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
// Removed `initState`
}
Some unsolicited advice:
- Remember to reset the allow/deny notifications in the settings or the "origin settings" button:
- I'd recommend migrating this code from
dart:html
topackage:web
, which is a more modern (and Wasm-compatible) js-interop layer. See the migration instructions.
Please, @BenjiFarquhar, let me know if this helps, so we can close this issue. Thanks!
from flutter.
Related Issues (20)
- mac-27 lost external connection phone device. HOT 2
- ui_web: fix incorrect JS interop (and probably migrate to extension types) HOT 1
- linux-62 lost external connection phone device. HOT 2
- [Macros] Waiting on support for MemberDeclarationBuilder.typesOf(ClassDeclaration.library) HOT 1
- ☂️: Impeller on Android supports 1P rendering plugins, with a clear migration path for others HOT 1
- mac-40 lost external connection phone device. HOT 2
- VideoPlayerWebOptions does not fully work on Edge HOT 13
- [Linux] Rows/Columns should render some combination of Flexible/Expanded children with flex values specified. HOT 8
- ListView inside several Containers inside Column ignores parent constraints HOT 2
- Check tha issue
- [Android]: App shows white screen after reopening the app in emulator running api 35 in release mode. HOT 15
- iOS VoiceOver accessibility regression: EditableText rotor actions only available when keyboard is focused HOT 6
- Incorrect Access Rights Error Despite Having Proper Access for Flutter Project HOT 1
- [video_player]Invalid videoComposition may cause the app crash HOT 6
- Flutter App is always crashing on Hot Reload after changing certain classes HOT 5
- [Impeller] new vetting of round rects is too strict HOT 1
- [shared_preferences] Enable Safe Reuse of Prefix Settings and Instance Checks HOT 2
- [animations]Using certain Curves with implicit animations may cause the program to throw an error
- RuntimeError: memory access out of bounds HOT 5
- Build fails on Linux missing sysprof-4 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter.