79525888

Date: 2025-03-21 15:26:44
Score: 2
Natty:
Report link

I have the same problem, I fixed like that:

Fist, I make a class and write all of function I use:

// /src/common/utils/web_alternative.dart
void usePathUrlStrategy() {}

dynamic get window => null;

After that, I use it to import:

// When I want to use html
import 'package:vinh/src/common/utils/web_alternative.dart' if (dart.library.html) 'dart:html' as html;
// When I want to use usePathUrlStrategy
import 'package:vinh/src/common/utils/web_alternative.dart' if (dart.library.html) 'package:flutter_web_plugins/flutter_web_plugins.dart' show usePathUrlStrategy;

I can use that like it:

if (kIsWeb) {
  usePathUrlStrategy();
  html.window;
}
Reasons:
  • Blacklisted phrase (1): I have the same problem
  • Whitelisted phrase (-2): I fixed
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): I have the same problem
  • Low reputation (0.5):
Posted by: Vinh