Skip to content

Commit

Permalink
5 build fail by device info plugin (#6)
Browse files Browse the repository at this point in the history
* 🔵 other: workflow fix

* 🐞 fix: slang string extension not import

* 🔵 other: clean up

---------

Co-authored-by: zhangyunjie <[email protected]>
  • Loading branch information
tom8zds and zhangyunjie authored Jul 4, 2024
1 parent 0ac6faf commit b6966fb
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jobs:
with:
toolchain: stable

- name: Set up java 17
uses: actions/setup-java@v4
with:
distribution: "zulu" # See 'Supported distributions' for available options
java-version: "17"

- name: Build Prepare
run: |
flutter pub get
Expand Down
2 changes: 1 addition & 1 deletion lib/common/device_info_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:localsend_rs/common/string_extensions.dart';
import 'package:localsend_rs/rust/actor/model.dart';
import 'package:slang/builder/model/enums.dart';
import 'package:slang/builder/utils/string_extensions.dart';
import 'package:uuid/uuid.dart';

import 'constants.dart';
Expand Down
74 changes: 74 additions & 0 deletions lib/common/string_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import 'package:collection/collection.dart';
import 'package:slang/builder/model/enums.dart';

extension StringExtensions on String {
/// capitalizes a given string
/// 'hello' => 'Hello'
/// 'Hello' => 'Hello'
/// '' => ''
String capitalize() {
if (isEmpty) return '';
return '${this[0].toUpperCase()}${substring(1).toLowerCase()}';
}

/// transforms the string to the specified case
/// if case is null, then no transformation will be applied
String toCase(CaseStyle? style) {
switch (style) {
case CaseStyle.camel:
return getWords()
.mapIndexed((index, word) =>
index == 0 ? word.toLowerCase() : word.capitalize())
.join('');
case CaseStyle.pascal:
return getWords().map((word) => word.capitalize()).join('');
case CaseStyle.snake:
return getWords().map((word) => word.toLowerCase()).join('_');
case null:
return this;
default:
print('Unknown case: $style');
return this;
}
}

/// de-DE will be interpreted as [de,DE]
/// normally, it would be [de,D,E] which we do not want
String toCaseOfLocale(CaseStyle style) {
return toLowerCase().toCase(style);
}

/// get word list from string input
/// assume that words are separated by special characters or by camel case
List<String> getWords() {
final input = this;
final StringBuffer buffer = StringBuffer();
final List<String> words = [];
final bool isAllCaps = input.toUpperCase() == input;

for (int i = 0; i < input.length; i++) {
final String currChar = input[i];
final String? nextChar = i + 1 == input.length ? null : input[i + 1];

if (_symbolSet.contains(currChar)) {
continue;
}

buffer.write(currChar);

final bool isEndOfWord = nextChar == null ||
(!isAllCaps && _upperAlphaRegex.hasMatch(nextChar)) ||
_symbolSet.contains(nextChar);

if (isEndOfWord) {
words.add(buffer.toString());
buffer.clear();
}
}

return words;
}
}

final RegExp _upperAlphaRegex = RegExp(r'[A-Z]');
final Set<String> _symbolSet = {' ', '.', '_', '-', '/', '\\'};
2 changes: 1 addition & 1 deletion lib/i18n/strings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// Locales: 2
/// Strings: 26 (13 per locale)
///
/// Built on 2024-07-03 at 15:38 UTC
/// Built on 2024-07-04 at 02:58 UTC
// coverage:ignore-file
// ignore_for_file: type=lint
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ dependencies:
flutter_riverpod: ^2.4.9
riverpod_annotation: ^2.3.3
shared_preferences: ^2.2.2
slang: ^3.28.0
slang_flutter: ^3.28.0
slang: ^3.31.0
slang_flutter: ^3.31.0
device_info_plus: ^10.1.0
uuid: ^4.4.0
equatable: ^2.0.5
Expand All @@ -70,7 +70,7 @@ dev_dependencies:
riverpod_generator: ^2.3.9
custom_lint: ^0.6.4
riverpod_lint: ^2.3.7
slang_build_runner: ^3.28.0
slang_build_runner: ^3.31.0
flutter_launcher_icons: "^0.13.1"
innosetup: ^0.1.3

Expand Down

0 comments on commit b6966fb

Please sign in to comment.