Skip to content

Instantly share code, notes, and snippets.

View bambinoua's full-sized avatar

BambinoUA bambinoua

  • Ukraine
View GitHub Profile
@bambinoua
bambinoua / color_gradient.dart
Created May 20, 2021 15:25
Utility class for generation list of gradient colors
import 'package:flutter/painting.dart';
/// Utility class for generation list of gradient colors.
class ColorGradient {
ColorGradient._();
/// Generates the list from `length` colors which starts from
/// `startColor` and ends with `endColor`.
///
/// The length must be greater than 0.
@bambinoua
bambinoua / main.dart
Last active October 26, 2021 07:25
Replace n occurrence of a substring in a string
void main() {
const subject = 'I have a dog. I have a cat. I have a bird.';
final result = replaceStringByOccurrence(subject, 'have', '*have no*', 0);
print(result);
}
/// Looks for `occurrence` of `search` in `subject` and replace it with `replace`.
///
/// The occurrence index is started from 0.
String replaceStringByOccurrence(
0 = Success
1 = Operation not permitted
2 = No such file or directory
3 = No such process
4 = Interrupted system call
5 = Input/output error
6 = No such device or address
7 = Argument list too long
8 = Exec format error
@bambinoua
bambinoua / image_remove_backgroun.dart
Created September 2, 2022 12:32 — forked from plateaukao/image_remove_backgroun.dart
image remove background in flutter
Future<Uint8List> _downloadImage() async {
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/$_filename');
if (file.existsSync()) {
var image = await file.readAsBytes();
return image;
} else {
var response = await http.get(_url,);
var bytes = response.bodyBytes;
@bambinoua
bambinoua / make_snapshot.dart
Created October 4, 2022 06:09
Makes a snhapshot of widget
import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() {
runApp(const MyApp());
}
@bambinoua
bambinoua / long_text_splitter.php
Created October 14, 2022 15:45
Split long text onto few lines of specified length
<?php
$count = 60;
$re = "/(?:((?>.{1,${count}}(?:(?<=[^\S\r\n])[^\S\r\n]?|(?=\r?\n)|$|[^\S\r\n]))|.{1,${count}})(?:\r?\n)?|(?:\r?\n|$))/";
$string = 'This function will always return an array even the if the text is not processed i.e. for already short text. The above code returns the unprocessed short text by adding it into array.';
echo trim(preg_replace($re, "$1\r\n", $string));
@bambinoua
bambinoua / OverlayableContainerOnLongPress_sample.dart
Created December 1, 2022 13:22 — forked from boeledi/OverlayableContainerOnLongPress_sample.dart
How to display an overlay on top of a particular item, present in a Scroll Area, on longPress?
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
///
/// Launch the application
///
runApp(Application());
}
// Main video widget.
class VideoState extends State {
Widget build(...) {
return Row(
childred: [
SideBar(), // can be hidden (depending on this overlay which can be created deeper should change its sze as VideoMonitor widget will also be resized.
VideoMonitor(), // contains VideoMonitorGrid
],
);
}
@bambinoua
bambinoua / downloadFile.dart
Created January 4, 2023 17:19 — forked from ajmaln/downloadFile.dart
Download file with progress in Dart/Flutter using 'http' package
import 'dart:typed_data';
import 'dart:io';
import 'package:http/http.dart';
import 'package:path_provider/path_provider.dart';
downloadFile(String url, {String filename}) async {
var httpClient = http.Client();
var request = new http.Request('GET', Uri.parse(url));
@bambinoua
bambinoua / always_scrollbar.dart
Created January 10, 2023 12:38 — forked from slightfoot/always_scrollbar.dart
Always Visible Scrollbar for Flutter - 4th March 2019
import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.indigo,