Skip to content

Instantly share code, notes, and snippets.

@dmslabsbr
Last active February 8, 2024 21:03
Show Gist options
  • Save dmslabsbr/ed2425c8793a6239d667658e4fab788f to your computer and use it in GitHub Desktop.
Save dmslabsbr/ed2425c8793a6239d667658e4fab788f to your computer and use it in GitHub Desktop.
get URL page parameters Flutter & Flutterflow
// Automatic FlutterFlow imports
import '/backend/schema/structs/index.dart';
import '/backend/schema/enums/enums.dart';
import '/actions/actions.dart' as action_blocks;
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'dart:html';
Future<String> getUrlParameters(String tag) async {
// Add your function code here!
print('html: ${window.location.href}');
print('parametro: $tag');
print("Uri.base: ${Uri.base}");
print("Uri.base.query: ${Uri.base.query}");
print(jsonEncode(Uri.base.queryParameters));
String ret = '';
if (tag.isNotEmpty) {
ret = Uri.base.queryParameters[tag] ?? '';
} else {
ret = Uri.base.query;
}
if (ret.isEmpty) {
String currentURL = window.location.href;
if (currentURL.contains('?') && currentURL.contains(tag)) {
// Converte a string de consulta em um Uri para facilitar o acesso aos parâmetros
Uri uri = Uri.parse(currentURL);
// Acessa o valor do parâmetro desejado
ret = uri.queryParameters[tag] ?? '';
} else {
ret = currentURL;
}
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment