Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>12.0</string>
</dict>
</plist>
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -472,7 +472,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -521,7 +521,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
Expand Down Expand Up @@ -54,11 +55,13 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
enableGPUValidationMode = "1"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
9 changes: 6 additions & 3 deletions example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import UIKit
import Flutter
import UIKit

@main
@objc class AppDelegate: FlutterAppDelegate {
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
}
}
29 changes: 25 additions & 4 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
Expand All @@ -24,6 +26,29 @@
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneClassName</key>
<string>UIWindowScene</string>
<key>UISceneConfigurationName</key>
<string>flutter</string>
<key>UISceneDelegateClassName</key>
<string>FlutterSceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -43,9 +68,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/lib/variants/currency_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CurrencyInput extends StatefulWidget {
class _CurrencyInputState extends State<CurrencyInput> {
final _controller = NumberEditingTextController.currency(
currencyName: 'JPY',
allowNegative: false,
allowNegative: true,
);

@override
Expand Down
20 changes: 19 additions & 1 deletion lib/src/parsed_number_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,29 @@ class ParsedNumberFormat {
}

num number = 0;
var isNegative = false;

for (final part in parts) {
final partResult = part.format(result, charPosition);
charPosition += partResult.offset;
result = partResult.value;
final resultNumber = partResult.number;
if (resultNumber != null) {
number += resultNumber;
if (part is RealPart && resultNumber <= 0) {
// Check if the formatted text contains a minus sign
final partText = result.text.substring(
charPosition - partResult.offset,
charPosition,
);
if (partText.startsWith('-')) {
isNegative = true;
}
}
if (isNegative && part is DecimalPart) {
number -= resultNumber;
} else {
number += resultNumber;
}
} else if (part is RealPart) {
return FormatResult(result, null);
} else if (part is DecimalPart) {
Expand All @@ -177,6 +192,9 @@ class ParsedNumberFormat {
}

String formatString(num value) {
if (value is double && (value.isNaN || value.isInfinite)) {
return '';
}
final result = StringBuffer();

for (final part in parts) {
Expand Down
24 changes: 19 additions & 5 deletions lib/src/parts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,18 @@ class StaticPart extends NumberFormatPart {
while (i < content.length && (position + i) <= v.text.length) {
if ((position + i) == v.text.length ||
content[i] != v.text[position + i]) {
v = v.replaced(TextRange.collapsed(position + i), content[i]);
// Check if the expected character exists right after (user inserted
// a character before the static content). If so, remove the inserted
// character instead of inserting the expected one.
if ((position + i + 1) < v.text.length &&
content[i] == v.text[position + i + 1]) {
v = v.replaced(
TextRange(start: position + i, end: position + i + 1),
'',
);
} else {
v = v.replaced(TextRange.collapsed(position + i), content[i]);
}
}
i++;
}
Expand Down Expand Up @@ -103,7 +114,7 @@ class RealPart extends NumberFormatPart {
final nextChar =
v.text.length == position + i + 1 ? null : v.text[position + i + 1];
if (g is WithGrouping && char == g.groupingSymbol) {
if (nextChar == null || !nextChar.isDigit) {
if (i == 0 || nextChar == null || !nextChar.isDigit) {
finished = true;
continue;
}
Expand Down Expand Up @@ -139,11 +150,14 @@ class RealPart extends NumberFormatPart {
number = numberText == '-' ? 0 : num.parse(numberText);
}
if (i != 0 && g is WithGrouping) {
final realPartLength = i;
for (var j = 0; j < realPartLength; j++) {
final hasMinusSign =
v.text[position] == '-' && allowNegative;
final digitLength = hasMinusSign ? i - 1 : i;
final digitStart = hasMinusSign ? 1 : 0;
for (var j = 0; j < digitLength; j++) {
if (j != 0 && j % g.groupSize == 0) {
v = v.replaced(
TextRange.collapsed(position + realPartLength - j),
TextRange.collapsed(position + digitStart + digitLength - j),
g.groupingSymbol,
);
i++;
Expand Down
Loading
Loading