Skip to content

Commit

Permalink
Added github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
VigneshSK17 committed Jun 25, 2023
1 parent 92b6940 commit cb9893e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 61 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy
on: [push]
jobs:
dist_macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.7.7'
channel: 'stable'
- name: Get dependencies
run: flutter pub get
- name: Build
run: flutter build macos
- name: Upload
uses: actions/upload-release-asset@v2.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./build/macos/Build/Products/Release/cubimer.app
asset_name: cubimer-${{ github.event.release.tag_name }}-macos
asset_content_type: binary/octet-stream
dist_windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.7.7'
channel: 'stable'
- name: Get dependencies
run: flutter pub get
- name: Build
run: flutter build windows
- name: Upload
uses: actions/upload-release-asset@v2.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./build/windows/runner/Release/cubimer.exe
asset_name: cubimer-${{ github.event.release.tag_name }}-macos
asset_content_type: binary/octet-stream
24 changes: 0 additions & 24 deletions lib/data/scramble.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import 'dart:math';

import 'package:cubimer/main.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:localstorage/localstorage.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:stop_watch_timer/stop_watch_timer.dart';

class Scramble {
Expand Down Expand Up @@ -61,9 +59,6 @@ class Scramble {
}

static int stringToTime(String timeStr) {
// return (double.parse(double.parse(timeStr).toStringAsFixed(2)) * 1000)
// .toInt();

if (timeStr.contains(':')) {
final times = timeStr.split(':');

Expand Down Expand Up @@ -211,31 +206,12 @@ class CurrentScramble extends StateNotifier<String> {
class ScrambleStore {
ScrambleStore();

// static Future<List<Scramble>> getScrambles() async {
// final prefs = await SharedPreferences.getInstance();

// final stringScrambles = prefs.getStringList("scrambles") ?? [];
// return stringScrambles
// .map((s) => Scramble.fromJson(jsonDecode(s)))
// .toList();
// }

static Future<List<Scramble>> getScrambles() async {
await storage.ready;
List<dynamic> scrambles = storage.getItem('scrambles') ?? [];
return scrambles.map((s) => Scramble.fromJson(jsonDecode(s))).toList();
}

// static Future<List<Scramble>> saveScrambles(List<Scramble> scrambles) async {
// final prefs = await SharedPreferences.getInstance();

// final stringScrambles =
// scrambles.map((s) => jsonEncode(s.toJson())).toList();
// await prefs.setStringList("scrambles", stringScrambles);

// return await getScrambles();
// }

static Future<void> saveScrambles(List<Scramble> scrambles) async {
final stringScrambles =
scrambles.map((s) => jsonEncode(s.toJson())).toList();
Expand Down
12 changes: 5 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import 'package:cubimer/widgets/scrambles_drawer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:localstorage/localstorage.dart';
import 'package:shared_preferences/shared_preferences.dart';

// TODO: Put scrambles in localstate
final scrambleListProvider =
StateNotifierProvider<ScrambleList, List<Scramble>>((ref) {
return ScrambleList([]);
Expand All @@ -16,10 +14,10 @@ final scrambleListProvider =
final currentScrambleProvider =
StateNotifierProvider<CurrentScramble, String>((ref) => CurrentScramble());

final storage = new LocalStorage('cubimer');
final storage = LocalStorage('cubimer');

void main() {
runApp(ProviderScope(child: MyApp()));
runApp(const ProviderScope(child: MyApp()));
}

class MyApp extends ConsumerWidget {
Expand Down Expand Up @@ -49,7 +47,7 @@ class MyApp extends ConsumerWidget {
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Cubimer'), // TODO: Make cooler
home: const MyHomePage(title: 'Cubimer'),
);
}
}
Expand Down Expand Up @@ -93,10 +91,10 @@ class _MyHomePageState extends ConsumerState<MyHomePage>
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title,
style: TextStyle(fontFamily: "PressStart2P")),
style: const TextStyle(fontFamily: "PressStart2P")),
// leading: const Icon(Icons.list),
),
drawer: ScramblesDrawer(),
drawer: const ScramblesDrawer(),
body: const Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
Expand Down
27 changes: 11 additions & 16 deletions lib/widgets/bottom_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ class _BottomBarState extends ConsumerState<BottomBar> {
return BottomAppBar(
child: Center(
child: Padding(
padding: EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
// TODO: Fix font sizing
child: FittedBox(
fit: BoxFit.fitWidth,
child: Text(ref.watch(currentScrambleProvider)),
),
),
Spacer(),
const Spacer(),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: FutureBuilder(
Expand All @@ -36,21 +35,18 @@ class _BottomBarState extends ConsumerState<BottomBar> {
alignment: WrapAlignment.spaceAround,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
// TODO: Fix dropdown
DropdownButton(
items: [
items: const [
DropdownMenuItem(child: Text("3x3"))
],
onChanged: (value) => print(
"hi"), // TODO: Change it to state
onChanged: (value) => (),
),
IconButton(
icon: Icon(Icons.delete),
icon: const Icon(Icons.delete),
onPressed: () {
if (ref
.watch(scrambleListProvider)
.length !=
0) {
.watch(scrambleListProvider)
.isNotEmpty) {
ref
.watch(
scrambleListProvider.notifier)
Expand All @@ -61,11 +57,10 @@ class _BottomBarState extends ConsumerState<BottomBar> {
},
),
IconButton(
icon: Icon(Icons.edit),
icon: const Icon(Icons.edit),
onPressed: () => ref
.watch(scrambleListProvider)
.length !=
0
.watch(scrambleListProvider)
.isNotEmpty
? showDialog(
context: context,
// TODO: Set up so that it uses most recent scramble
Expand All @@ -78,7 +73,7 @@ class _BottomBarState extends ConsumerState<BottomBar> {
: null,
), // TODO: Add popup
IconButton(
icon: Icon(Icons.redo),
icon: const Icon(Icons.redo),
onPressed: () => ref
.read(currentScrambleProvider
.notifier)
Expand Down
18 changes: 4 additions & 14 deletions lib/widgets/center_timer.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:cubimer/data/scramble.dart';
import 'package:cubimer/main.dart';
import 'package:cubimer/widgets/scrambles_drawer.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:localstorage/localstorage.dart';
import 'package:stop_watch_timer/stop_watch_timer.dart';

enum TimerState { NEW, WAIT, RUNNING, STOP, END }
Expand All @@ -17,13 +15,12 @@ class CenterTimer extends ConsumerStatefulWidget {
ConsumerState<ConsumerStatefulWidget> createState() => _CenterTimerState();
}

// TODO: Add controller to change colors
class _CenterTimerState extends ConsumerState<CenterTimer> {
var _textStyle =
TextStyle(color: Color(0xff1D1B1E), fontFamily: "RobotoMono");
const TextStyle(color: Color(0xff1D1B1E), fontFamily: "RobotoMono");

var _timerState = TimerState.NEW;
var _timer = StopWatchTimer();
final _timer = StopWatchTimer();

void _toggleTextStyle() {
setState(() {
Expand All @@ -32,7 +29,7 @@ class _CenterTimerState extends ConsumerState<CenterTimer> {
TextStyle(color: Colors.green, fontFamily: _textStyle.fontFamily);
} else if (_timerState == TimerState.STOP) {
_textStyle = TextStyle(
color: Color(0xff1D1B1E), fontFamily: _textStyle.fontFamily);
color: const Color(0xff1D1B1E), fontFamily: _textStyle.fontFamily);
}
});
}
Expand All @@ -52,8 +49,6 @@ class _CenterTimerState extends ConsumerState<CenterTimer> {
}

void onTapDownController(TapDownDetails _) async {
print("Holding");

setState(() {
if (_timerState == TimerState.NEW) {
_timerState = TimerState.WAIT;
Expand All @@ -74,13 +69,9 @@ class _CenterTimerState extends ConsumerState<CenterTimer> {
.read(scrambleListProvider.notifier)
.add(time: _timer.rawTime.value, scramble: currScramble);
}

// TODO: Store scramble time
}

void onTapUpController(TapUpDetails _) async {
print("Stopped holding");

setState(() {
if (_timerState == TimerState.WAIT) {
_timerState = TimerState.RUNNING;
Expand All @@ -93,7 +84,6 @@ class _CenterTimerState extends ConsumerState<CenterTimer> {
if (_timerState == TimerState.RUNNING) {
_timer.onStartTimer();
} else if (_timerState == TimerState.NEW) {
// TODO: Add way to randomize scramble
ref.read(currentScrambleProvider.notifier).state =
CurrentScramble.genScramble();
}
Expand All @@ -110,7 +100,7 @@ class _CenterTimerState extends ConsumerState<CenterTimer> {
child: FittedBox(
fit: BoxFit.fitWidth,
child: Padding(
padding: EdgeInsets.all(32),
padding: const EdgeInsets.all(32),
child: StreamBuilder<int>(
stream: _timer.rawTime,
initialData: 0,
Expand Down

0 comments on commit cb9893e

Please sign in to comment.