小编Mor*_*ens的帖子

在 Flutter 项目中使用 Grpc Web

我希望有人可以帮助解决我目前正在创建一个适用于 Web 和移动设备的 Flutter 应用程序的问题,并且我想使用 GRPC 和 WebGrpc。使用 Grpc 一切都运行良好,但使用 Web Grpc 时出现错误

   if (kIsWeb) {
    print("flutter web");
    clientChannel =
        GrpcWebClientChannel.xhr(Uri.parse('http://192.168.2.146:8880'));
    AuthClient(clientChannel).authenticate(AuthenticationRequest()
      ..login = "Apfel"
      ..password= "Hello").then((res) => print(res)).catchError((err) => print(err));
  } else {
    print("flutter mobil");
    clientChannel = ClientChannel('192.168.2.146',
        port: 3009,
        options:
        ChannelOptions(credentials: ChannelCredentials.insecure()));
  }
Run Code Online (Sandbox Code Playgroud)

我收到以下错误预期为“ClientChannel”类型的值,但得到了“GrpcWebClientChannel”类型之一

dart grpc flutter grpc-web grpc-dart

5
推荐指数
0
解决办法
1557
查看次数

在 EventHandler 中调用 this.StateHasChanged

我有以下问题。我创建了一个事件并订阅了它,现在我希望在事件触发时 UI 发生变化。

 using System;
 using MintWebApp.Data;
 using MintWebApp.Models;
 using Microsoft.AspNetCore.Components;
 namespace WebApp.UI.Core
 {
    public partial class AppHeader
    {
        public string status { get; set; }
        [Inject]
        public StateService state { get; set; }

        EventHandler<string> onStatusChanged= (sender, eventArgs) => {

            //Here i get the error, I can't access this and status
            status = eventArgs;
            this.StateHasChanged();
            Console.WriteLine(eventArgs.PatientName);
        };

        protected override void OnInitialized() => state.StatusHandler += onStatusChanged;
    }

}
Run Code Online (Sandbox Code Playgroud)

我收到此错误字段初始值设定项无法引用非静态字段、方法或属性“AppHeader.patientContext”

关键字“this”在当前上下文中不可用

如何订阅事件并更新 UI

c# razor .net-core blazor blazor-server-side

1
推荐指数
1
解决办法
1762
查看次数

将服务注入分区剃刀组件类

我想在剃刀组件中拆分代码。Html 标记和逻辑。我真的是新的 C#。当我像这样尝试时

TaskManagement.razor.cs:

using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;
using MintWebApp.Services;
using MintDataService;

namespace WebApp.Pages 
{
    partial class TaskManagement 
    {
        public TaskService _taskService;

        public TaskManagement(TaskService taskService)
        {
            _taskService = taskService;
        }

        protected override async Task OnInitializedAsync()
        {
            MintTaskFromJson task = await _taskService.GetExampleTask();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

MissingMethodException: No parameterless constructor defined for type 
'WebApp.Pages.TaskManagement'.
Run Code Online (Sandbox Code Playgroud)

哪个是将服务注入partinal类而不在razor文件中注入服务的最佳方式

c# .net-core blazor

0
推荐指数
1
解决办法
1212
查看次数

标签 统计

.net-core ×2

blazor ×2

c# ×2

blazor-server-side ×1

dart ×1

flutter ×1

grpc ×1

grpc-dart ×1

grpc-web ×1

razor ×1