Skip to content

Instantly share code, notes, and snippets.

View ayoubzulfiqar's full-sized avatar
👁️‍🗨️
Implementing

Sensei ayoubzulfiqar

👁️‍🗨️
Implementing
  • Freelancer (Open to Collaborations!)
View GitHub Profile
@ayoubzulfiqar
ayoubzulfiqar / api_calling.dart
Last active February 8, 2022 16:56
These are the basic methods to call api in dart
// The main maethod (just return the widget name to fetch the data from different methods)
import 'package:flutter/material.dart';
import 'package:flutterx/demo.dart';
import 'package:flutterx/photos.dart';
void main() {
runApp(const Experiment());
}
@ayoubzulfiqar
ayoubzulfiqar / api_methods.dart
Created February 11, 2022 18:24
These gist contain all the mehods to http request
// Model for Json DATA
class Posts {
Posts({
required this.userId,
required this.id,
required this.title,
required this.body,
});
late final int userId;
@ayoubzulfiqar
ayoubzulfiqar / rock_paper_scissors.dart
Created February 14, 2022 11:39
Rock-Paper-Scissors game against computer
void main(){
while (true) {
print("Rock, Paper, Scissors Shoot!");
String playerMove = getPlayerMove();
if (playerMove == "Quit") {
return;
}
print("You played $playerMove");
// accesing and requesting
Future<List<Directory>?>? _externalStorageDirectory; // this will go in future in future builder
// this will go in onPresssed if you wanna use button to request everything
void requestExternalStorageDirectory(StorageDirectory type) {
// Method
// Initialize it into the initState
var files = <FileSystemEntity>[];
Future<List<FileSystemEntity>> dirContents(Directory dir) async {
var completer = Completer<List<FileSystemEntity>>();
var lister = dir.list(recursive: false, followLinks: false);
lister.listen((file) async {
FileStat f = file.statSync();
@ayoubzulfiqar
ayoubzulfiqar / date_time_format.dart
Created March 21, 2022 14:25
This is the snippet for to get date and time without using any external libraries such as Intl. which is not bad to use but this snippet is perfect for o get date and time or sometime jsut date. Much better than using library.
// Define a simple format function from scratch
String dateTimeformat({required DateTime time, bool dateOnly = false}) {
String year = time.year.toString();
// Add "0" on the left if month is from 1 to 9
String month = time.month.toString().padLeft(2, '0');
// Add "0" on the left if day is from 1 to 9
String day = time.day.toString().padLeft(2, '0');
@ayoubzulfiqar
ayoubzulfiqar / temperatureConversionFormulas.dart
Created May 6, 2022 09:40
Thias gist contain all the conversion formulas for the temperature.
// c represents the Celsius value which you will add according to mode of conversion you want.
// r represents the Rankine value which you will add according to mode of conversion you want
// k represents the Kelvin value which you will add according to mode of conversion you want.
// f represents the Fahrenheit value which you will add according to mode of conversion you want
class Temperature {
double celsiusToFahrenheit(num c) {
return (c * 9 / 5 + 32);
}
@ayoubzulfiqar
ayoubzulfiqar / responsive.dart
Last active July 26, 2022 13:27
This gist contain mediaQuery properties to access in the stateless widget in flutter which is usually you have to write full syntex but with this is easily accessible. it's usually an extention on BuildContext. Work is still in progress
import 'dart:ui';
import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';
extension Responsive on BuildContext {
// width = yourDeviceWidth, height = yourDeviceHeight
@ayoubzulfiqar
ayoubzulfiqar / json.dart
Last active June 17, 2022 19:01
accessing data from json in flutter include both local and online method. usually local json consider as a demo data model for project.
// demo json file. --------Note the image is from local assest file. so use Image.assest method in dart to access. for network use Image.network in flutter
// place json file outside of lib folder
[
{
"id": 0,
"name": "NexMart - Casual Sneakers",
"category": "NOP",
"imageUrl": "img/header_onboarding/first_header.png",
"oldPrice": "1899",
"price": "799"
@ayoubzulfiqar
ayoubzulfiqar / android_permissions.xml
Created June 24, 2022 16:53
This Gits contain all the permission of android app which will you place in your flutter app inside AndroidManifest.xml file.
<uses-permission android:name="android.permission.ACCESS_ALL_DOWNLOADS"/>
<uses-permission android:name="android.permission.ACCESS_BLUETOOTH_SHARE"/>
<uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM"/>
<uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/>
<uses-permission android:name="android.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY"/>
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER"/>
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED"/>
<uses-permission android:name="android.permission.ACCESS_DRM_CERTIFICATES"/>
<uses-permission android:name="android.permission.ACCESS_EPHEMERAL_APPS"/>
<uses-permission android:name="android.permission.ACCESS_FM_RADIO"/>