Created
January 13, 2023 04:50
-
-
Save gistlyn/818c6c080dc349c99f6ef384f528fdce to your computer and use it in GitHub Desktop.
flutter-app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flutter pub add servicestack | |
flutter pub get |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Options: | |
Date: 2023-01-13 13:45:10 | |
Version: 6.41 | |
Tip: To override a DTO option, remove "//" prefix before updating | |
BaseUrl: https://localhost:5001 | |
//GlobalNamespace: | |
//AddServiceStackTypes: True | |
//AddResponseStatus: False | |
//AddImplicitVersion: | |
//AddDescriptionAsComments: True | |
//IncludeTypes: | |
//ExcludeTypes: | |
//DefaultImports: package:servicestack/servicestack.dart | |
*/ | |
import 'package:servicestack/servicestack.dart'; | |
class HelloResponse implements IConvertible | |
{ | |
String? result; | |
HelloResponse({this.result}); | |
HelloResponse.fromJson(Map<String, dynamic> json) { fromMap(json); } | |
fromMap(Map<String, dynamic> json) { | |
result = json['result']; | |
return this; | |
} | |
Map<String, dynamic> toJson() => { | |
'result': result | |
}; | |
getTypeName() => "HelloResponse"; | |
TypeContext? context = _ctx; | |
} | |
// @Route("/hello") | |
// @Route("/hello/{Name}") | |
class Hello implements IReturn<HelloResponse>, IConvertible | |
{ | |
String? name; | |
Hello({this.name}); | |
Hello.fromJson(Map<String, dynamic> json) { fromMap(json); } | |
fromMap(Map<String, dynamic> json) { | |
name = json['name']; | |
return this; | |
} | |
Map<String, dynamic> toJson() => { | |
'name': name | |
}; | |
createResponse() => HelloResponse(); | |
getResponseTypeName() => "HelloResponse"; | |
getTypeName() => "Hello"; | |
TypeContext? context = _ctx; | |
} | |
TypeContext _ctx = TypeContext(library: 'localhost', types: <String, TypeInfo> { | |
'HelloResponse': TypeInfo(TypeOf.Class, create:() => HelloResponse()), | |
'Hello': TypeInfo(TypeOf.Class, create:() => Hello()), | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:servicestack/client.dart'; | |
import 'dtos.dart'; | |
const baseUrl = "https://localhost:5001"; | |
var client = JsonServiceClient(baseUrl); | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
// This is the theme of your application. | |
// | |
// Try running your application with "flutter run". You'll see the | |
// application has a blue toolbar. Then, without quitting the app, try | |
// changing the primarySwatch below to Colors.green and then invoke | |
// "hot reload" (press "r" in the console where you ran "flutter run", | |
// or simply save your changes to "hot reload" in a Flutter IDE). | |
// Notice that the counter didn't reset back to zero; the application | |
// is not restarted. | |
primarySwatch: Colors.blue, | |
), | |
home: const HelloFlutter(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class HelloFlutter extends StatefulWidget { | |
const HelloFlutter({super.key, required this.title}); | |
// This widget is the home page of your application. It is stateful, meaning | |
// that it has a State object (defined below) that contains fields that affect | |
// how it looks. | |
// This class is the configuration for the state. It holds the values (in this | |
// case the title) provided by the parent (in this case the App widget) and | |
// used by the build method of the State. Fields in a Widget subclass are | |
// always marked "final". | |
final String title; | |
@override | |
State<StatefulWidget> createState() => HelloFlutterState(); | |
} | |
class HelloFlutterState extends State<HelloFlutter> { | |
//State for this widget | |
String result = ""; | |
var myController = TextEditingController(); | |
@override | |
void initState() { | |
super.initState(); | |
myController.addListener(callService); | |
} | |
void callService() { | |
client.get(Hello(name: myController.text)).then((value) => setState(() { | |
result = value.result!; | |
})); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
// Here we take the value from the MyHomePage object that was created by | |
// the App.build method, and use it to set our appbar title. | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
const Text('Hello API', style: TextStyle(fontWeight: FontWeight.bold,fontSize: 24.0),), | |
Container( | |
margin: const EdgeInsets.only(left:100.0,right:100.0), | |
child: TextField( | |
decoration: const InputDecoration( | |
border: OutlineInputBorder(), | |
hintText: 'World', | |
), | |
controller: myController, | |
), | |
), | |
Text('Result: $result', | |
style: const TextStyle(fontStyle: FontStyle.italic),) | |
], | |
), | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment