From 9f00bc049be7027a0220fb7978d3a94baff4d718 Mon Sep 17 00:00:00 2001 From: 223880 Date: Mon, 29 Jul 2024 06:39:19 -0300 Subject: [PATCH] Add Flutter support --- README.md | 2 +- lib/sdk/flutter.dart | 42 ++++++++++++++++++++++++++++++++++++++++++ pubspec.yml | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 lib/sdk/flutter.dart diff --git a/README.md b/README.md index 3c6e818..a3962bc 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ ## Roadmap - [x] Dockerfile -- [ ] Compatible with Flutter for build apps (mobile) +- [x] Compatible with Flutter for build apps (mobile) - [ ] RBF - [ ] Full RBF - [ ] API diff --git a/lib/sdk/flutter.dart b/lib/sdk/flutter.dart new file mode 100644 index 0000000..dc3c53a --- /dev/null +++ b/lib/sdk/flutter.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; +import 'dart:convert'; + +void main() { + runApp(MyApp()); +} + +class MyApp extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar(title: Text('Dart Library in Flutter')), + body: Center( + child: FutureBuilder( + future: fetchData(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return CircularProgressIndicator(); + } else if (snapshot.hasError) { + return Text('Error: ${snapshot.error}'); + } else { + return Text('Data: ${snapshot.data}'); + } + }, + ), + ), + ), + ); + } + + Future fetchData() async { + final response = await http.get(Uri.parse('https://jsonplaceholder.typicode.com/posts/1')); + if (response.statusCode == 200) { + var jsonResponse = jsonDecode(response.body); + return jsonResponse['title']; + } else { + throw Exception('Failed to load data'); + } + } +} diff --git a/pubspec.yml b/pubspec.yml index 4853217..695569a 100644 --- a/pubspec.yml +++ b/pubspec.yml @@ -16,6 +16,7 @@ dependencies: http: '^0.14.0' cupertino_icons: ^1.0.0 bdk: '^0.31.2' + flutter: '^3.22.3' # Dev dependencies for the project dev_dependencies: