我想知道如何使用 Koin 库正确确定依赖范围。
由于 Google 推荐了单一Activity架构,因此AndroidX 导航库已成为通过轻松交换Fragments来促进这一点的关键库。
典型的现代 Android 应用程序在包和/或Gradle模块中具有多个分离的功能。
这些功能模块提供了一个可以在根图中用作嵌套图的图。(见图)
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_graph"
app:startDestination="@id/mainFragment">
<include app:graph="@navigation/nav_graph_feature_a" />
<include app:graph="@navigation/nav_graph_feature_b" />
<fragment
android:id="@+id/mainFragment"
android:name="com.example.androidx_navigation.MainFragment"
android:label="MainFragment"
tools:layout="@layout/fragment_main">
<action
android:id="@+id/action_mainFragment_to_featureAFragment1"
app:destination="@id/nav_graph_feature_a" />
<action
android:id="@+id/action_mainFragment_to_featureBFragment1"
app:destination="@id/nav_graph_feature_b" />
</fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)
应遵守以下规则:
更具体地说:
如何在 Koin 中实现这一目标?
请注意,共享依赖项不仅限于 ViewModel。
我应该能够在我的范围内共享任何任意类。
android koin android-architecture-navigation navigation-architecture koin-scope
我AutoSuggestBox在Windows Phone 8.1 上显示结果时遇到问题.我正在使用MVVM Light将我的itemsource绑定到Autosuggestbox.
<AutoSuggestBox Header="Van" Text="{Binding SearchTextFrom, Mode=TwoWay}" ItemsSource="{Binding suggestionFrom}">
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding description}"/>
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="TextChanged">
<core:InvokeCommandAction Command="{Binding SearchChangedFrom}">
</core:InvokeCommandAction>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</AutoSuggestBox>
Run Code Online (Sandbox Code Playgroud)
我的ViewModel
private RelayCommand _SearchChangedFrom;
public RelayCommand SearchChangedFrom
{
get
{
return _SearchChangedFrom ?? (_SearchChangedFrom = new RelayCommand(
async () =>
{
if (string.IsNullOrWhiteSpace(user.countrycode))
{
Debug.WriteLine("Could not autocomplete the country because there was no country code provided.");
return;
}
var predictions = await _Service.GetGoogleMapsSuggestionFromQuery(user.countrycode, SearchTextFrom);
suggestionFrom = predictions;
}));
} …Run Code Online (Sandbox Code Playgroud) 我正在编写一个Flutter具有广泛单元测试覆盖范围的应用程序。
我正在使用Mockito来模拟我的课程。
来自Java( Android) 世界,在那里我可以使用Mockito链接调用以在后续调用中返回不同的值。
我希望这能奏效。
import 'package:test/test.dart';
import 'package:mockito/mockito.dart';
void main() {
test("some string test", () {
StringProvider strProvider = MockStringProvider();
when(strProvider.randomStr()).thenReturn("hello");
when(strProvider.randomStr()).thenReturn("world");
expect(strProvider.randomStr(), "hello");
expect(strProvider.randomStr(), "world");
});
}
class StringProvider {
String randomStr() => "real implementation";
}
class MockStringProvider extends Mock implements StringProvider {}
Run Code Online (Sandbox Code Playgroud)
但是它抛出:
Expected: 'hello'
Actual: 'world'
Which: is different.
Run Code Online (Sandbox Code Playgroud)
我发现有效的唯一工作方式是跟踪自己。
void main() {
test("some string test", () {
StringProvider strProvider = MockStringProvider();
var invocations = 0; …Run Code Online (Sandbox Code Playgroud) 正如我之前所说的(RGB 到飞利浦 Hue (HSB)),我仍然没有放弃将简单的 RGB 值转换为飞利浦 Hue 可接受的值的希望。
iPhone 和 Android 的官方应用程序允许您从随机照片中选择一种颜色,色调会相应地进行自我调整。所以一定有某种公式。
然而,这一次我想我刚刚在网上这篇有趣的文章中找到了这个公式:
我一直在尝试将他的解释转换为 Java 语言,但没有得到想要的结果。有谁知道出了什么问题?
根据记录,我使用的是飞利浦 Hue 灯泡。
public static List<Double> getRGBtoXY(Color c) {
// For the hue bulb the corners of the triangle are:
// -Red: 0.675, 0.322
// -Green: 0.4091, 0.518
// -Blue: 0.167, 0.04
double[] normalizedToOne = new double[3];
float cred, cgreen, cblue;
cred = c.getRed();
cgreen = c.getGreen();
cblue = c.getBlue();
normalizedToOne[0] = (cred / 255);
normalizedToOne[1] = (cgreen / 255);
normalizedToOne[2] …Run Code Online (Sandbox Code Playgroud) 我正在建立一个Windows Phone 8.1项目,我正在使用MVVM Light Libraries only库.我创建了一个PCL项目来保存我的ViewModel,以便以后可以将它们用于Windows Store项目.
但我在标题中收到错误?
我的App.xaml
<Application
x:Class="Roadsmart.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Roadsmart"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:Roadsmart.Lib.ViewModels;assembly=Roadsmart.Lib"
mc:Ignorable="d">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/RoadSmartWindowsPhoneStyle.xaml"/>
<ResourceDictionary Source="Resources/Dictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
<viewModels:ViewModelLocator
x:Key="Locator"
d:IsDataSource="True"/>
</ResourceDictionary>
</Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)
我在Windows Phone项目中引用了Roadsmart.Lib.

我的Lib项目属性

但是Blend能够找到我的ViewModel吗?

但我无法建立,运行.我也试过清洗.

有人知道我做错了什么吗?
提前致谢
我正在尝试JSON从API.
API 返回JSON转义引号,因为数据代表用户的报价。
test("escaped quoted json test", () {
var s = '''{"quote": "\"a quote from a user\""}''';
var b = json.decode(s);
expect(b["quote"], "\"a quote from a user\"");
});
Run Code Online (Sandbox Code Playgroud)
但是这会抛出:
FormatException: Unexpected character (at character 13)
{"quote": ""a quote from a user""}
顺便说一句,JSON 是有效的:
{"quote": "\"a quote from a user\""}
Run Code Online (Sandbox Code Playgroud)
我Dart该如何正确处理这个问题?
提前致谢。
我可能遗漏了一些明显的东西,但我无法在 Android Studio 中显示“部署预览”按钮。
\n\n但是,如果我打开Android Compose Samples,我就会看到它们。
\n我检查了它们的依赖关系并将它们应用到我的应用程序中,但我仍然看不到它们。
\nimplementation "androidx.compose.runtime:runtime:1.1.0-rc01"\nimplementation "androidx.compose.material:material:1.1.0-rc01"\nimplementation "androidx.compose.foundation:foundation:1.1.0-rc01"\nimplementation "androidx.compose.foundation:foundation-layout:1.1.0-rc01"\nimplementation "androidx.compose.ui:ui-tooling:1.1.0-rc01"\nimplementation "androidx.compose.animation:animation:1.1.0-rc01"\nimplementation \'androidx.activity:activity-compose:1.1.0-rc02\'\ndebugImplementation "androidx.compose.ui:ui-test-manifest:1.1.0-rc01"\nRun Code Online (Sandbox Code Playgroud)\n为了让此部署预览显示,我缺少什么?
\n需要明确的是,我可以毫无问题地显示预览。
\n但没有部署预览按钮。
我注意到该按钮仅出现在\'com.android.application\'模块中,而不出现在\'com.android.library\'模块 \xc2\xaf_(\xe3\x83\x84)_/\xc2\xaf中
android ×2
c# ×2
dart ×2
flutter ×2
mvvm ×2
android-architecture-navigation ×1
autosuggest ×1
colors ×1
image ×1
java ×1
json ×1
koin ×1
koin-scope ×1
mockito ×1
mvvm-light ×1
philips-hue ×1
unit-testing ×1
xaml ×1