Skip to content

Instantly share code, notes, and snippets.

View kirshiyin89's full-sized avatar

Kirshi Yin kirshiyin89

View GitHub Profile
@kirshiyin89
kirshiyin89 / StartPage.dart
Created August 24, 2020 18:50
Snippet for displaying the GridView.
Widget _buildGridView(BuildContext context, List<ServerInfo> serverInfo) {
return GridView.count(
primary: false,
padding: const EdgeInsets.all(1.5),
crossAxisCount: determineCrossAxisCount(context),
childAspectRatio: 1.2,
mainAxisSpacing: 1.0,
crossAxisSpacing: 1.0,
children: _prepareServerInfoCards(serverInfo), //new Cards()
shrinkWrap: true,
@kirshiyin89
kirshiyin89 / util.dart
Created August 24, 2020 18:53
A utility class for the screen size.
import 'package:flutter/material.dart';
int determineCrossAxisCount(BuildContext context) {
int _crossAxisCount = 1;
final double screenWidthSize = MediaQuery.of(context).size.width;
if (screenWidthSize > 820) {
_crossAxisCount = 4;
} else if (screenWidthSize > 720) {
_crossAxisCount = 3;
} else if (screenWidthSize > 520) {
@kirshiyin89
kirshiyin89 / StartPage.dart
Created August 24, 2020 18:56
The StartPage preparing the server info cards for displaying.
List<Widget> _prepareServerInfoCards(List<ServerInfo> serverInfo) {
List<Widget> serverInfoCells = [];
// we can call the rest service here?
for (ServerInfo category in serverInfo) {
serverInfoCells.add(_getServerInfoCard(category));
}
return serverInfoCells;
}
Container _getServerInfoCard(ServerInfo serverInfo) {
@kirshiyin89
kirshiyin89 / StartPage.dart
Created August 24, 2020 18:57
Creating the Table Widget.
Widget _createStatusTable(ServerInfo serverInfo) {
if (serverInfo.notAvailable()) {
return new Text('Server unreachable');
}
return Table(
border: TableBorder.all(
color: Colors.black26, width: 1, style: BorderStyle.none),
children: _createStatusCells(serverInfo.services));
}
@kirshiyin89
kirshiyin89 / StartPage.dart
Created August 24, 2020 19:00
TextStyle for service info.
TextStyle _getStyleByServiceStatus(bool running) {
if (!running) {
return TextStyle(fontStyle: FontStyle.italic);
}
return TextStyle();
}
@kirshiyin89
kirshiyin89 / StartPage.dart
Created August 24, 2020 19:03
Color for the Cards depending on the services status.
Color _getColorByServerStatus(ServerInfo info) {
if (info.running()) {
return Colors.teal[600];
} else {
return Colors.red[200];
}
}
@kirshiyin89
kirshiyin89 / dataservice.dart
Created August 24, 2020 19:05
The DataService consuming the response from the back-end.
import 'package:myapp/serverinfo.dart';
import 'dart:js' as js;
import 'package:http/http.dart' as http;
import 'dart:async';
import 'dart:convert';
Future<List<ServerInfo>> fetchServerInfo() async {
final response = await http.get("http://localhost:8080/api");
if (response.statusCode == 200) {
@kirshiyin89
kirshiyin89 / main.dart
Last active August 25, 2020 13:28
The main application class.
import 'package:flutter/material.dart';
import 'package:myapp/dataservice.dart';
import 'dart:async';
import 'package:myapp/serverinfo.dart';
import 'package:myapp/startpage.dart';
void main() {
runApp(MyApp());
@kirshiyin89
kirshiyin89 / build.gradle
Created August 25, 2020 13:54
The gradle properties for Spring Boot.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
@kirshiyin89
kirshiyin89 / build.gradle
Last active September 1, 2020 21:47
Gradle dependencies.
repositories {
mavenCentral()
maven {
url 'https://github.com/psiegman/mvn-repo/raw/master/releases'
}
}
dependencies {
compile 'com.rabbitmq:amqp-client:5.9.0'
compile group: 'nl.siegmann.epublib', name: 'epublib-core', version: '3.1'