Combining Flutter frontend with .NET Core backend for Android and iOS

前端 未结 3 1949
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-04 17:24

Currently working for a company that use .NET (not Core) but want to switch to .NET Core and thought to do so by creating an app with a Flutter.io frontend and .NET Core backend

相关标签:
3条回答
  • 2021-02-04 17:35

    ServiceStack v5.1 has added native support for Dart and Flutter where you can can generate an end-to-end Typed API from a remote URL, e.g:

    $ npm install -g @servicestack/cli
    
    $ dart-ref https://www.techstacks.io
    

    This is supported for .NET Core 2.0 as well as any of .NET's popular hosting options. The example above generates a Typed API for the .NET Core 2.0 TechStacks project.

    The HelloFlutter App shows an example of calling a .NET Core 2.0 and a classic ASP.NET App back-end using a Typed API:

    To call any Service you just need to import the servicestack Dart package and the generated DTOs, e.g:

    import 'package:servicestack/client.dart';
    import 'techstacks.dtos.dart';
    

    Then create an instance of JsonServiceClient configured with your remote URL, e.g:

    var client = new JsonServiceClient("https://www.techstacks.io");
    

    Which you can then call within your Flutter widget like any async API:

    class HelloFlutter extends StatefulWidget {
      @override
      State<StatefulWidget> createState() => new HelloFlutterState();
    }
    
    class HelloFlutterState extends State<HelloFlutter> {
      //State for this widget
      String result = "";
    
      @override
      Widget build(BuildContext context) {
    
          //...
          new RaisedButton(
            child: new Text("Async"),
            onPressed: () async {
              var r = await client .get(new Hello(name: "Async"));
              setState(() {
                result = r.result;
              });
            },
          ),
    
          //...
          new Text(result),
      }
    }
    

    For more info see docs for ServiceStack's native Dart support.

    0 讨论(0)
  • 2021-02-04 17:40

    I love using Flutter with my .Net Web Api back ends. The web api support in Flutter is great as they have built in JSON serialization support. the combination is beautiful and I am hooked on this powerful framework

    0 讨论(0)
  • 2021-02-04 17:46

    .NET/core is for API, flutter is for native apps. They are completely unrelated.

    One side will have no impact on the other one. So yes, you can use both.

    0 讨论(0)
提交回复
热议问题