Skip to content

Commit

Permalink
Add flutter with CI
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Feb 28, 2024
1 parent 9e20960 commit 6c16a68
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 338 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
*.dart text eol=lf
90 changes: 90 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: CI

on:
push:
branches: [master]

pull_request:

workflow_dispatch:

env:
FLUTTER_VERSION: 3.16.9

jobs:
formatting:
name: "Check Formatting"
runs-on: ubuntu-22.04

steps:
- name: Checkout repo
uses: actions/checkout@v4

- uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: 'stable'

- name: Install dependencies
run: flutter pub get

- name: Check formatting
run: dart format -o none --set-exit-if-changed lib/* test/*

analysis:
name: "Static Analysis"
runs-on: ubuntu-22.04

steps:
- name: Checkout repo
uses: actions/checkout@v4

- uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: 'stable'

- name: Install dependencies
run: flutter pub get

- name: Run analysis
run: flutter analyze

build:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2022
build-option: "windows"
artifact-name: Dashboard2024-Windows
- os: macos-14
build-option: "macos"
artifact-name: Dashboard2024-macOS
- os: ubuntu-22.04
build-option: "linux"
artifact-name: Dashboard2024-linux
name: "Build - ${{ matrix.artifact-name }}"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install flutter deps
if: ${{ matrix.build-option == 'linux' }}
run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build libgtk-3-dev
- name: Setup flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
cache: true
cache-path: ${{ runner.tool_cache }}/flutter/${{ matrix.build-option }}

- name: Get dependencies
run: flutter pub get

- name: Build app
run: flutter build ${{ matrix.build-option }}
225 changes: 34 additions & 191 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,207 +1,50 @@
import 'package:flutter/material.dart';
// import 'package:flutter_box_transform/flutter_box_transform.dart';
import 'package:nt4/nt4.dart';
import 'package:logger/logger.dart';
import 'package:flutter/services.dart'; // For SystemChrome and SystemUiMode
import 'package:dotted_border/dotted_border.dart'; // For Dotted Borders
// import 'package:fullscreen_window/fullscreen_window.dart';

void main() {
var logger = Logger();
Map<String, dynamic> widget = {"name": "Pink Widget", "Draggable": true, };
widget['Type'] = "RPM";

List<Map<String, dynamic>> activeWidgets = [widget];

activeWidgets.add({"name": "Blue Widget", "Draggable": true, "Type": "Voltage"});

// Accessing values in order
StringBuffer logMessage = StringBuffer();
for (var entry in activeWidgets) {
for (var key in entry.keys) {
logMessage.write('$key: ${entry[key]} \n');
}
}
logger.i(logMessage);

// networkTables();
runApp(MyApp());
// var fullScreenState = false;
// toggleFullScreen(fullScreenState);
networkTables();
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);

final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
var windowWidth = MediaQuery.of(context).size.width;
var windowHeight = MediaQuery.of(context).size.height;
var logger = Logger();


return MaterialApp(
home: Scaffold(
key: _scaffoldKey, // Assign the GlobalKey to the Scaffold
appBar: AppBar(
title: const Text('FRC 4788 Dashboard'),
),
drawer: Drawer(
backgroundColor: Colors.grey,
child: Column(
children: [
Draggable(
data: DragData(id: 'pinkWidget'),
feedback: PinkWidget(
windowHeight: windowHeight,
windowWidth: windowWidth,
),
childWhenDragging: PinkWidgetDraggingFiller(
windowHeight: windowHeight,
windowWidth: windowWidth,
),
child: PinkWidget(
windowHeight: windowHeight,
windowWidth: windowWidth,
),
onDragStarted: () {
// Close the drawer when dragging starts
_scaffoldKey.currentState?.openEndDrawer();
},
),
],
home: Center(
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.pink,
title: const Text('4788 Dashboard'),
),
),
body: DragTarget<DragData>(
builder: (BuildContext context, List<DragData?> candidateData,
List<dynamic> rejectedData) {
// Build the UI for the DragTarget
return Container(
color: const Color.fromARGB(255, 255, 124, 168),
width: windowWidth,
height: windowHeight,
);
},
onWillAccept: (dynamic data) {
// Always return true to accept all data
// activeWidgets.append(data);
return true;
},
onAccept: (dynamic data) {
logger.i('Accepted data: $data');
// Handle the accepted data
},
),
),
);
}
}

class DragData {
final String id;

DragData({required this.id});
}

class PinkWidget extends StatefulWidget {
final double windowHeight;
final double windowWidth;

const PinkWidget(
{Key? key, required this.windowHeight, required this.windowWidth})
: super(key: key);

@override
State<PinkWidget> createState() => _PinkWidgetState();
}

class _PinkWidgetState extends State<PinkWidget> {
late double windowWidth = widget.windowWidth;
late double windowHeight = widget.windowHeight;

@override
Widget build(BuildContext context) {
return Material(
//Material to remove the orange underline: https://stackoverflow.com/questions/47114639/yellow-lines-under-text-widgets-in-flutter
child: Container(
width: (windowWidth - 100) / 6,
height: (windowHeight - 100) / 6,
decoration: BoxDecoration(
color: Colors.pink,
border: Border.all(
color: Colors.black,
width: 2.0,
),
),
child: const Center(
child: Text(
"Placeholder Title",
style: TextStyle(
color: Colors.black,
fontSize: 20.0,
fontWeight: FontWeight.bold,
body: Container(
margin: const EdgeInsets.all(100.0),
padding: const EdgeInsets.all(20.0),
height: 100,
width: 400,
decoration: BoxDecoration(
color: Colors.pinkAccent,
border: Border.all(
color: Colors.black,
width: 2,
),
),
child: const Text('Welcome to 4788 Dashboard'),
),
),
),
);
}
}

class PinkWidgetDraggingFiller extends StatelessWidget {
final double windowHeight;
final double windowWidth;

const PinkWidgetDraggingFiller(
{Key? key, required this.windowHeight, required this.windowWidth})
: super(key: key);

@override
Widget build(BuildContext context) {
return Container(
width: (windowWidth - 100) / 6,
height: (windowHeight - 100) / 6,
decoration: BoxDecoration(
color: Colors.pinkAccent,
border: Border.all(
color: Colors.black,
width: 2.0,
),
),
);
}
}

class DottedRectWidget extends StatelessWidget {
final double windowHeight;
final double windowWidth;

const DottedRectWidget(
{Key? key, required this.windowHeight, required this.windowWidth})
: super(key: key);

@override
Widget build(BuildContext context) {
return ClipRect(
child: DottedBorder(
dashPattern: const [10, 5],
borderType: BorderType.Rect,
borderPadding: const EdgeInsets.all(1),
strokeWidth: 4,
color: const Color.fromARGB(121, 187, 178, 178),
child: Container(
height: 100,
width: 200,
color: Colors.white,
),
),
);
}
}

void networkTables() async {
var logger = Logger();
// Connect to NT4 server at 10.47.88.2

NT4Client client = NT4Client(
serverBaseAddress: '10.47.88.2',
onConnect: () {
Expand All @@ -213,22 +56,22 @@ void networkTables() async {
);

// Subscribe to a topic
NT4Subscription exampleSub = client.subscribePeriodic('/SmartDashboard/DB/');
NT4Subscription exampleSub =
client.subscribePeriodic('/SmartDashboard/DB/Slider 0');

// Recieve data from subscription with a callback or stream
exampleSub.listen((data) => logger.i('Recieved data from callback: $data'));
// exampleSub.stream(yieldAll: true);

await for (Object? data in exampleSub.stream(yieldAll: true)) {
await for (Object? data in exampleSub.stream()) {
logger.i('Recieved data from stream: $data');
}
}

void toggleFullScreen(bool fullScreenState) {
var logger = Logger();
fullScreenState = !fullScreenState;
logger.i(fullScreenState);
if (fullScreenState) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
} else {}
}
// void toggleFullScreen(bool fullScreenState) {
// fullScreenState = !fullScreenState;
// if (fullScreenState) {
// FullscreenWindow.enterFullscreen();
// } else {
// FullscreenWindow.exitFullscreen();
// }
// }
8 changes: 0 additions & 8 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
}
2 changes: 0 additions & 2 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
4 changes: 0 additions & 4 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import FlutterMacOS
import Foundation

import screen_retriever
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
Loading

0 comments on commit 6c16a68

Please sign in to comment.