Skip to content

Instantly share code, notes, and snippets.

View wilburx9's full-sized avatar

Wilberforce Uwadiegwu wilburx9

View GitHub Profile
@wilburx9
wilburx9 / main.dart
Last active November 8, 2020 01:40
Convert Apple devices utsname.machine to Json. See https://gist.github.com/adamawolf/3048717 for the updated list
import "dart:convert";
// Convert Apple devices utsname.machine to Json. See https://gist.github.com/adamawolf/3048717 for the updated list
void main() {
final splits = sss.split("\n");
final json = Map<String, String>();
splits.forEach((s) {
final k = s.split(":");
if (k.length == 2) {
@wilburx9
wilburx9 / dismissible_animated.dart
Last active January 16, 2023 07:02
Animated Flutter Dismissible
Tween<Offset> _offSetTween = Tween(
begin: Offset(1, 0),
end: Offset.zero,
);
...
@override
Widget build(BuildContext context) {
return Scaffold(
...
@wilburx9
wilburx9 / dismissible_handle_dismiss.dart
Last active February 18, 2021 17:30
Handle dismiss action of Flutter Dismissible.
handleDismiss(DismissDirection direction, int index) {
// Get a reference to the swiped item
final swipedEmail = items[index];
// Remove it from the list
items.removeAt(index);
String action;
if (direction == DismissDirection.startToEnd) {
deleteItem();
@wilburx9
wilburx9 / dismissible_swipe_confirm.dart
Last active February 18, 2021 17:30
Confirming a Flutter Dismissible swipe event
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
var item = items[index];
return Dismissible(
...
@wilburx9
wilburx9 / card_utils.dart
Last active March 4, 2021 22:12
A set of functions for validating payment card expiry date
static String validateDate(String value) {
if (value.isEmpty) {
return Strings.fieldReq;
}
int year;
int month;
// The value contains a forward slash if the month and year has been
// entered.
if (value.contains(new RegExp(r'(\/)'))) {
@wilburx9
wilburx9 / card_utils.dart
Last active July 3, 2024 11:34
Validating card number with Luhn algorithm in dart/flutter
static String validateCardNumWithLuhnAlgorithm(String input) {
if (input.isEmpty) {
return Strings.fieldReq;
}
input = getCleanedNumber(input);
if (input.length < 8) { // No need to even proceed with the validation if it's less than 8 characters
return Strings.numberIsInvalid;
}
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:news_aggreator/home_page.dart';
class PostDetails extends StatefulWidget {
PostDetails(this.post);
final Post post;
@override
State<StatefulWidget> createState() => new _PostDetailsState(post);
Widget _getPostWidgets(int index) {
var post = postList[index];
return new GestureDetector(
onTap: () {
openDetailsUI(post);
},
child: new Container(
margin: const EdgeInsets.symmetric(horizontal: 5.0, vertical: 5.0),
child: new Card(
elevation: 3.0,
class _MyHomePageState extends State<MyHomePage> {
bool _isRequestSent = false;
List<Post> postList = [];
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
class Post {
String title;
String summary;
String thumbUrl;
int timeStamp;
String url;
Post(this.title, this.summary, this.thumbUrl, this.timeStamp, this.url);
static Post getPostFrmJSONPost(dynamic jsonObject) {