Skip to content

Instantly share code, notes, and snippets.

View kirshiyin89's full-sized avatar

Kirshi Yin kirshiyin89

View GitHub Profile
@kirshiyin89
kirshiyin89 / ServerInfo.java
Created August 24, 2020 17:51
ServerInfo DTO
public class ServerInfo {
public final String name;
public final List<ServiceInfo> services;
public ServerInfo(String name, List<ServiceInfo> services) {
this.name = name;
this.services = services;
}
@kirshiyin89
kirshiyin89 / ServiceInfo.java
Created August 24, 2020 17:54
The Service Info DTO.
public class ServiceInfo {
public final String name;
public final boolean running;
public ServiceInfo(String name, boolean running) {
this.name = name;
this.running = running;
}
@kirshiyin89
kirshiyin89 / DataService.java
Created August 24, 2020 18:17
The DataService.java processing the server info and mapping it to the final result.
public List<ServerInfo> getServerInfo() {
List<ServerInfo> result = new ArrayList<>();
Map<String, String> serverData = getServerData();
for (Map.Entry<String, String> info : serverData.entrySet()) {
result.add(new ServerInfo(info.getKey(), map(info.getValue())));
}
return result;
}
private static List<ServiceInfo> map(String data) {
@kirshiyin89
kirshiyin89 / ServiceInfo.dart
Created August 24, 2020 18:40
The ServiceInfo dto hodling information on the services status.
class ServiceInfo {
const ServiceInfo({this.name, this.running});
final String name;
final bool running;
String status() {
if (running) {
return "running";
@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];
}
}