- worst update eu west
This commit is contained in:
		
							
								
								
									
										83
									
								
								lib/utils/ParseDeepLink.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								lib/utils/ParseDeepLink.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,83 @@
 | 
			
		||||
import 'package:f0ckapp/providers/MediaProvider.dart';
 | 
			
		||||
import 'package:f0ckapp/screens/DetailView.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
 | 
			
		||||
 | 
			
		||||
Map<String, RegExp> routes = {
 | 
			
		||||
  //'login': RegExp(r'^/login/?$'),
 | 
			
		||||
  //'user': RegExp(r'^/user/(?<user>.*)$'),
 | 
			
		||||
  'complex': RegExp(
 | 
			
		||||
    r'^/?'
 | 
			
		||||
    r'(?:tag/(?<tag>.+?))?'
 | 
			
		||||
    r'(?:/user/(?<username>.+?)/(?<set>f0cks|favs))?'
 | 
			
		||||
    r'(?:/(?<media>image|audio|video))?'
 | 
			
		||||
    r'(?:/(?<id>\d+))?'
 | 
			
		||||
    r'$',
 | 
			
		||||
  ),
 | 
			
		||||
  //'random': RegExp(r'^/random$'),
 | 
			
		||||
  //'search': RegExp(r'^/search/?$'),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Map<String, dynamic> parseDeepLink(Uri? uri) {
 | 
			
		||||
  if (uri == null) {
 | 
			
		||||
    return {};
 | 
			
		||||
  }
 | 
			
		||||
  String url = uri.toString().replaceAll("https://f0ck.me", "");
 | 
			
		||||
 | 
			
		||||
  for (final MapEntry<String, RegExp> entry in routes.entries) {
 | 
			
		||||
    final String routeName = entry.key;
 | 
			
		||||
    final RegExp pattern = entry.value;
 | 
			
		||||
    final RegExpMatch? match = pattern.firstMatch(url.toString());
 | 
			
		||||
    if (match != null) {
 | 
			
		||||
      Map<String, String> params = <String, String>{};
 | 
			
		||||
      for (String name in match.groupNames) {
 | 
			
		||||
        params[name] = match.namedGroup(name) ?? '';
 | 
			
		||||
      }
 | 
			
		||||
      return {'route': routeName, 'params': params};
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return {};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Future<void> handleComplexDeepLink(
 | 
			
		||||
  Map<String, String> params,
 | 
			
		||||
  BuildContext context,
 | 
			
		||||
  WidgetRef ref,
 | 
			
		||||
  ScrollController scrollController,
 | 
			
		||||
) async {
 | 
			
		||||
  final media = params['media'];
 | 
			
		||||
  const validMediaTypes = {'audio', 'video', 'image'};
 | 
			
		||||
  if (media != null && validMediaTypes.contains(media)) {
 | 
			
		||||
    ref.read(mediaProvider.notifier).setType(media);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  final idParam = params['id'];
 | 
			
		||||
  if (idParam == null || idParam.isEmpty) return;
 | 
			
		||||
 | 
			
		||||
  final int? id = int.tryParse(idParam);
 | 
			
		||||
  if (id == null) return;
 | 
			
		||||
 | 
			
		||||
  final mediaState = ref.read(mediaProvider);
 | 
			
		||||
  final index = mediaState.mediaItems.indexWhere((item) => item.id == id);
 | 
			
		||||
  if (index == -1) {
 | 
			
		||||
    await ref.read(mediaProvider.notifier).loadMedia(id: id + 50);
 | 
			
		||||
 | 
			
		||||
    final updatedState = ref.read(mediaProvider);
 | 
			
		||||
    final updatedIndex = updatedState.mediaItems.indexWhere(
 | 
			
		||||
      (item) => item.id == id,
 | 
			
		||||
    );
 | 
			
		||||
    print(updatedIndex.toString());
 | 
			
		||||
    if (updatedIndex == -1) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool? navigationResult = await Navigator.push(
 | 
			
		||||
    context,
 | 
			
		||||
    MaterialPageRoute(builder: (_) => DetailView(initialItemId: id)),
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  if (navigationResult == true) {
 | 
			
		||||
    scrollController.jumpTo(0);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user