Skip to content

Instantly share code, notes, and snippets.

View VB10's full-sized avatar
🏠
Working from home

Veli Bacik VB10

🏠
Working from home
View GitHub Profile
@VB10
VB10 / error_manage_widget_with_exception.dart
Created May 28, 2024 22:22
Error Handling from widget with exception manager
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class User {
final String? name;
final int? age;
const User(this.name, this.age);
bool isEmpty() {
@VB10
VB10 / number_extension.dart
Created May 17, 2024 11:18
Take a count of digit in any number
extension NumberExtension on num {
/// This method is used to take the first [count] digits of the number.
///
/// if the number is 59342394234 and [count] is 2, the result will be 59.
/// number less than [count] will return 0.
num takeDigits(int count) {
final value = toString();
final isValueLengthValid = value.length >= count;
if (!isValueLengthValid) return 0;
return num.parse(value.substring(0, count));
import 'package:flutter/material.dart';
import 'package:vbaseproject/features/v2/demo/home_veli_view.dart';
mixin HomeVeliMixin on State<HomeVeliView> {
void showErrorMessage();
void fetchUserDeteail({required String id}) {
const response = true;
if (!response) return;
showErrorMessage();
final class NetworkManager: NetworkManagerCore {
var config: NetworkConfig = .init(baseUrl: "")
/// Send your request without model paramaters
/// - Parameters:
/// - path: NetworkPath value
/// - method: HTTPMethod value
/// - type: Decoded model
/// - Returns: Success encoded model or
func send<T: Decodable>(path: NetworkPath, method: HTTPMethod, type: T.Type) async -> Result<T?, Error> {
@VB10
VB10 / future_timeout.dart
Last active September 28, 2023 14:44
Timeout
extension FutureExtension<T> on Future<T> {
Future<T?> timeoutOrNull({
Duration timeOutDuration = const Duration(seconds: 10),
bool enableLogger = true,
}) async {
try {
final response = await timeout(timeOutDuration);
return response;
} catch (e) {
if (enableLogger) CustomLogger.log('$T $e');
extension IterableExtension<T> on Iterable<T?> {
List<T> makeSafe() {
return where((element) => element != null).cast<T>().toList();
}
}
class VB10ViewModel {
List<User> dummyListToSafe() {
final userList = <User?>[
const User(),
extension on String {
/// Decode your [jsonString] value with safety
Future<dynamic> safeJsonDecodeCompute() async {
try {
return await compute<String, dynamic>(
jsonDecode,
this,
);
} catch (e) {
Logger().e('Json decode error');
"explorer.fileNesting.patterns": {
"pubspec.yaml": ".flutter-plugins, .packages, .dart_tool, .flutter-plugins-dependencies, .metadata, .packages, pubspec.lock, build.yaml, analysis_options.yaml, all_lint_rules.yaml",
".gitignore": ".gitattributes, .gitmodules, .gitmessage, .mailmap, .git-blame*",
"readme.*": "authors, backers.md, changelog*, citation*, code_of_conduct.md, codeowners, contributing.md, contributors, copying, credits, governance.md, history.md, license*, maintainers, readme*, security.md, sponsors.md",
"*.dart": "$(capture).g.dart, $(capture).freezed.dart",
},
"[dart]": {
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.rulers": [
@VB10
VB10 / int_extension_status_code.dart
Created June 30, 2023 11:05
flutter status code extension
extension IntExtension on int? {
StatusCode get httpStatusCode {
if (this == null) return StatusCode.unknown;
switch (this!) {
case < 200:
return StatusCode.continue_;
case >= 200 && <= 300:
return StatusCode.ok;
case 401:
@VB10
VB10 / add_comment_all_open_issues.py
Created June 13, 2023 10:31
send comment all issues to your repo with using chatgpt
import requests
import json
# GitHub API'ya gönderilecek olan veriler
base_url = "https://api.github.com/repos/{owner}/{repo}"
owner = "vb10"
repo = "2023-staj"
comment_body = f"""Merhaba arkadaşlar, sizler için elimden geldiğince herkese yazdım, LinkedIn postları paylaştım ve elimden gelen bir çok arkadaşa erişip staj bulmasına yardımcı oldum. Bu saate kadar size verebileceğim 'ben olsaydım' diyeceğim:
- Bu repoyu LinkedIn'de paylaşıp sadece kendim için değil, benim gibi arkadaşlar için staj arıyoruz demeniz.