<![CDATA[SooXT]]>https://sooxt98.space/https://sooxt98.space/favicon.pngSooXThttps://sooxt98.space/Ghost 3.37Sat, 21 Mar 2026 09:55:56 GMT60<![CDATA[The most codeless way to write Rest API in Flutter (Retrofit + Freezed)]]>

What you get from here? Reduced code and autocomplete from model

First, i have an API https://yourawesomeurl.com/user that returns the following result, so lets make it useable in flutter;

{
    "status": 200,
    "message": "fetch successfully!",
    "data": {
        "name": "
]]>
https://sooxt98.space/the-most-codeless-way-to-write-flutter-api/60508fea8f90c303918298adTue, 16 Mar 2021 11:06:32 GMT
The most codeless way to write Rest API in Flutter (Retrofit + Freezed)

What you get from here? Reduced code and autocomplete from model

First, i have an API https://yourawesomeurl.com/user that returns the following result, so lets make it useable in flutter;

{
    "status": 200,
    "message": "fetch successfully!",
    "data": {
        "name": "Sheldon",
        "age": 12
    }
}

Setting Up

dependencies:
  freezed_annotation: ^0.14.1
  retrofit: ^1.3.4+1
  json_annotation: ^4.0.0
  dio: ^4.0.0-beta7
  equatable: ^2.0.0

dev_dependencies:
  build_runner: ^1.11.5
  freezed: ^0.14.1
  json_serializable: ^4.0.2
  retrofit_generator: ^1.4.1+3

Template

base_response.dart

import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';

part 'base_response.g.dart';

@JsonSerializable(genericArgumentFactories: true)
class BaseResponse<T> extends Equatable {
  final String status;
  final T data;
  final String message;

  const BaseResponse({
    this.status,
    this.data,
    this.message,
  });

  factory BaseResponse.fromJson(
    Map<String, dynamic> json,
    T Function(Object json) fromJsonT,
  ) {
    return _$BaseResponseFromJson<T>(json, fromJsonT);
  }

  Map<String, dynamic> toJson(
    Map<String, dynamic> Function(T value) toJsonT,
  ) {
    return _$BaseResponseToJson<T>(this, toJsonT);
  }

  @override
  List<Object> get props => [
        status,
        data,
        message,
      ];
}

user_model.dart

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:flutter/foundation.dart';

part 'user_model.freezed.dart';
part 'user_model.g.dart';

@freezed
class UserModel with _$UserModel {
  const factory UserModel({required String name, required int age}) =
      _UserModel;

  factory UserModel.fromJson(Object? json) =>
      _$UserModelFromJson(json as Map<String, dynamic>);
}

api.dart

import 'package:dio/dio.dart';
import 'package:yourawesomeproject/models/user_model.dart';
import 'package:retrofit/retrofit.dart';

import 'api_response.dart';

part 'api.g.dart';

@RestApi(baseUrl: "https://yourawesomeurl.com")
abstract class RestClient {
  factory RestClient(Dio dio, {String baseUrl}) = _RestClient;

  @GET("/user")
  Future<ApiResponse<UserModel>> getUser();
}

Usage

Run this command to generate all the codes

> flutter pub run build_runner build
void main() async {
  final dio = Dio();
  
  // Optional: Due to self sign cert issue
  (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
      (HttpClient client) {
    client.badCertificateCallback =
        (X509Certificate cert, String host, int port) => true;
    return client;
  };

  final client = RestClient(dio);

  client.getUser().then((it) => print(it.data!.name));

  runApp(MyApp());
}

That's it, it will print out Sheldon

]]>
<![CDATA[Custom flutter material colors]]>
import 'dart:ui';
import 'package:flutter/material.dart';

MaterialColor createMaterialColor(Color color) {
  List strengths = <double>[.05];
  Map<int, Color> swatch = {};
  final int r = color.red, g = color.green, b = color.blue;

  for (int i = 1; i < 10; i++) {
    strengths.add(0.1 * i);
  }
  strengths.forEach(
]]>
https://sooxt98.space/custom-flutter-material-colors/5fa17a49159ae81545282d27Thu, 13 Aug 2020 18:26:07 GMT
import 'dart:ui';
import 'package:flutter/material.dart';

MaterialColor createMaterialColor(Color color) {
  List strengths = <double>[.05];
  Map<int, Color> swatch = {};
  final int r = color.red, g = color.green, b = color.blue;

  for (int i = 1; i < 10; i++) {
    strengths.add(0.1 * i);
  }
  strengths.forEach((strength) {
    final double ds = 0.5 - strength;
    swatch[(strength * 1000).round()] = Color.fromRGBO(
      r + ((ds < 0 ? r : (255 - r)) * ds).round(),
      g + ((ds < 0 ? g : (255 - g)) * ds).round(),
      b + ((ds < 0 ? b : (255 - b)) * ds).round(),
      1,
    );
  });
  return MaterialColor(color.value, swatch);
}

Usage

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: createMaterialColor(Color(0xFF223344)),
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}
]]>
<![CDATA[VR Hackathon (Smart Factory)]]>The most crowded hackathon I had ever attend.

Although we did not get into Top3, it was fun. I had learned how to corporate & distribute tasks among my three team members and come up with a working MVP in just two days half. Our project is set up and

]]>
https://sooxt98.space/vr-hackathon-smart-factory/5fa17a49159ae81545282d26Fri, 11 Jan 2019 19:16:18 GMT

The most crowded hackathon I had ever attend.

Although we did not get into Top3, it was fun. I had learned how to corporate & distribute tasks among my three team members and come up with a working MVP in just two days half. Our project is set up and display in MMU Centre For Digital. Home.

Pitch Deck

]]>
<![CDATA[ErRUNd]]>Another FoodPanda clone + community feature.

This is not my idea. But this is my MVP!

ErRUNd is an app that provides a platform for people to offer help and request help. Whether you’re a teacher, a student, a stay-at-home mum or an office worker, you can always ask someone

]]>
https://sooxt98.space/errund/5fa17a49159ae81545282d25Fri, 11 Jan 2019 19:16:12 GMT

Another FoodPanda clone + community feature.

This is not my idea. But this is my MVP!

ErRUNd is an app that provides a platform for people to offer help and request help. Whether you’re a teacher, a student, a stay-at-home mum or an office worker, you can always ask someone to run errands for you, or be the one to help! That means, people switch roles in building up this community.

We believe that by offering a little help to each other, we can create a better Malaysia, a better place to live in.

ErRUNd]]>
<![CDATA[3 Days of Code MMU Hackathon (FaceTendance)]]>The first hackathon in my campus πŸ˜‹

My first hackathon without sleeping. We hack whole day long until the next day morning pitching session.

Theme of this hackathon: Data, Finance, Education.

As I mentioned in the title, this is an app for attendance but with face recognition feature. So every lectures

]]>
https://sooxt98.space/3-days-of-code-mmu-hackathon/5fa17a49159ae81545282d23Fri, 11 Jan 2019 19:16:08 GMT

The first hackathon in my campus πŸ˜‹

My first hackathon without sleeping. We hack whole day long until the next day morning pitching session.

Theme of this hackathon: Data, Finance, Education.

As I mentioned in the title, this is an app for attendance but with face recognition feature. So every lectures in university can simply take students' attendance without calling their name one by one or need students to sign on a paper everyday.

Tech: NodeJs, ReactNative, Python
]]>
<![CDATA[RocketMMU]]>Automatically authenticate campus captive portal in background mode when connects to open wifi in campus.

The application is created to help students from Multimedia University (MMU) to connect the campus WiFi network without having to manually login their account every time.

Tech: ReactNative & Java

There is a background service

]]>
https://sooxt98.space/rocketmmu/5fa17a49159ae81545282d24Fri, 11 Jan 2019 10:09:19 GMT

Automatically authenticate campus captive portal in background mode when connects to open wifi in campus.

The application is created to help students from Multimedia University (MMU) to connect the campus WiFi network without having to manually login their account every time.

Tech: ReactNative & Java

There is a background service which detects the wifi connection status. And it is written in Java that bridge with ReactNative UI.

Demo Video

RocketMMU]]>
<![CDATA[UniSZA-MMU Hackathon (Swipyness)]]>My very first hackathon (Oct '17)

I couldn't imagine we did impress the judges and get the 1st prize πŸŽ‰πŸŽ‰πŸŽ‰ The theme for this hackathon is 'Happiness'. So, we planned to design a tinder like App called 'Swipyness'. The app allows users to discover new friends & things by swiping.

]]>
https://sooxt98.space/unisza-mmu-hackathon-swipy/5fa17a49159ae81545282d22Thu, 10 Jan 2019 18:26:25 GMT

My very first hackathon (Oct '17)

I couldn't imagine we did impress the judges and get the 1st prize πŸŽ‰πŸŽ‰πŸŽ‰ The theme for this hackathon is 'Happiness'. So, we planned to design a tinder like App called 'Swipyness'. The app allows users to discover new friends & things by swiping. And also can purchase each others artwork.

Prototype

We use ReactNative to implement the UI/UX.

Pitch Deck

Source Code

https://github.com/sooxiaotong/Swipyness

]]>
<![CDATA[Syntax highlighting test]]>
import 'dart:async';

const news = '<gathered news goes here>';
const oneSecond = Duration(seconds: 1);

// Imagine that this function is more complex and slow. :)
Future<String> gatherNewsReports() =>
    Future.delayed(oneSecond, () => news);

Future<void> printDailyNewsDigest() async {
  var newsDigest = await gatherNewsReports();
  print(newsDigest)
]]>
https://sooxt98.space/highlight-test/5fa17a49159ae81545282d21Thu, 10 Jan 2019 06:14:48 GMT
import 'dart:async';

const news = '<gathered news goes here>';
const oneSecond = Duration(seconds: 1);

// Imagine that this function is more complex and slow. :)
Future<String> gatherNewsReports() =>
    Future.delayed(oneSecond, () => news);

Future<void> printDailyNewsDigest() async {
  var newsDigest = await gatherNewsReports();
  print(newsDigest);
}

main() {
  printDailyNewsDigest();
}
.test {
    opacity: 0;
}
]]>