Skip to content

Commit 4a49d61

Browse files
committed
Update URL and Path Navigation
- Set URL strategy. - Set initial route generation correctly.
1 parent a856460 commit 4a49d61

File tree

7 files changed

+44
-7
lines changed

7 files changed

+44
-7
lines changed

lib/main.dart

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
import 'package:flutter/foundation.dart';
12
import 'package:flutter/material.dart';
3+
// ignore: depend_on_referenced_packages
4+
import 'package:flutter_web_plugins/url_strategy.dart';
25
import 'package:minimal/pages/pages.dart';
36
import 'package:responsive_framework/responsive_framework.dart';
47

58
void main() {
9+
WidgetsFlutterBinding.ensureInitialized();
10+
11+
if (kIsWeb) {
12+
usePathUrlStrategy();
13+
}
14+
615
runApp(const MyApp());
716
}
817

@@ -24,12 +33,28 @@ class MyApp extends StatelessWidget {
2433
child: child!,
2534
),
2635
initialRoute: '/',
36+
onGenerateInitialRoutes: (initialRoute) => [
37+
MaterialPageRoute(
38+
settings: RouteSettings(name: initialRoute),
39+
builder: (context) {
40+
String sanitizedRoute =
41+
initialRoute != '/' && initialRoute.startsWith('/')
42+
? initialRoute.substring(1)
43+
: initialRoute;
44+
45+
return BouncingScrollWrapper.builder(
46+
context, buildPage(sanitizedRoute),
47+
dragWithMouse: true);
48+
})
49+
],
2750
onGenerateRoute: (RouteSettings settings) {
28-
return MaterialPageRoute(builder: (context) {
29-
return BouncingScrollWrapper.builder(
30-
context, buildPage(settings.name ?? ''),
31-
dragWithMouse: true);
32-
});
51+
return MaterialPageRoute(
52+
settings: RouteSettings(name: '/${settings.name}'),
53+
builder: (context) {
54+
return BouncingScrollWrapper.builder(
55+
context, buildPage(settings.name ?? ''),
56+
dragWithMouse: true);
57+
});
3358
},
3459
debugShowCheckedModeBanner: false,
3560
);

linux/flutter/generated_plugin_registrant.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <url_launcher_linux/url_launcher_plugin.h>
910

1011
void fl_register_plugins(FlPluginRegistry* registry) {
12+
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
13+
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
14+
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
1115
}

linux/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
url_launcher_linux
67
)
78

89
list(APPEND FLUTTER_FFI_PLUGIN_LIST

macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import FlutterMacOS
66
import Foundation
77

88
import path_provider_foundation
9+
import url_launcher_macos
910

1011
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
1112
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
13+
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
1214
}

pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ version: 1.6.0
44
publish_to: none
55

66
environment:
7-
sdk: ">=3.0.0 <4.0.0"
8-
flutter: ">=3.0.0"
7+
sdk: '>=3.4.0 <4.0.0'
8+
flutter: ">=3.24.0"
99

1010
dependencies:
1111
flutter:
@@ -17,6 +17,7 @@ dependencies:
1717
google_fonts: ^6.2.1
1818
animations: ^2.0.11
1919
loading_gifs: ^0.3.0
20+
url_launcher: ^6.3.0 # Requires setup.
2021

2122
dev_dependencies:
2223
flutter_test:

windows/flutter/generated_plugin_registrant.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <url_launcher_windows/url_launcher_windows.h>
910

1011
void RegisterPlugins(flutter::PluginRegistry* registry) {
12+
UrlLauncherWindowsRegisterWithRegistrar(
13+
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
1114
}

windows/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
url_launcher_windows
67
)
78

89
list(APPEND FLUTTER_FFI_PLUGIN_LIST

0 commit comments

Comments
 (0)