Skip to content

Commit

Permalink
Url fixes (NickM-27#22)
Browse files Browse the repository at this point in the history
* Update path strategy

* Ensure location is always saved correctly

* Use conditional path strategy
  • Loading branch information
NickM-27 authored May 18, 2022
1 parent 2b854b7 commit 7930ff7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
9 changes: 8 additions & 1 deletion web/lib/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ class SwatchApi {
_swatchHost = "localhost:4500";
} else {
final location = (getHref() ?? "").replaceAll("http://", "");
_swatchHost = location.substring(0, location.indexOf("/"));

final pathStart = location.indexOf("/");

if (pathStart == -1) {
_swatchHost = location;
} else {
_swatchHost = location.substring(0, pathStart);
}
}

return _singleton;
Expand Down
1 change: 1 addition & 0 deletions web/lib/ext/url_strategy/extension_url_strategy.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'extension_url_strategy_noop.dart' if (dart.library.html) 'extension_url_strategy_web.dart';
3 changes: 3 additions & 0 deletions web/lib/ext/url_strategy/extension_url_strategy_noop.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void usePathUrlStrategy() {
// noop
}
5 changes: 5 additions & 0 deletions web/lib/ext/url_strategy/extension_url_strategy_web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

void usePathUrlStrategy() {
setUrlStrategy(PathUrlStrategy());
}
3 changes: 2 additions & 1 deletion web/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';
import 'package:swatch/ext/extension_navigator.dart';
import 'package:swatch/ext/url_strategy/extension_url_strategy.dart';
import 'package:swatch/routes/route_color_playground.dart';
import 'package:swatch/routes/route_dashboard.dart';
import 'package:swatch/routes/route_settings.dart';
import 'package:swatch/theme/theme_helper.dart';

void main() {
usePathUrlStrategy();
runApp(const SwatchApp());
}

Expand Down
12 changes: 12 additions & 0 deletions web/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: "direct main"
description:
Expand All @@ -95,6 +100,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.4"
lints:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ dependencies:
flutter:
sdk: flutter

flutter_web_plugins:
sdk: flutter

# UI
cupertino_icons: ^1.0.2
collapsible_sidebar: ^2.0.1+2
Expand Down
2 changes: 0 additions & 2 deletions web/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:swatch/main.dart';
import 'package:swatch/models/config.dart';

void main() {
Expand Down

0 comments on commit 7930ff7

Please sign in to comment.