Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SduiServiceImpl extends SduiServiceBase {
}
}
}

```

## Creating Screens
Expand Down Expand Up @@ -121,6 +122,8 @@ SduiWidgetData()
Display text with styling:
```dart
SduiWidgetData()


..type = WidgetType.TEXT
..stringAttributes['text'] = 'Hello World'
..textStyle = (TextStyleData()
Expand Down
175 changes: 175 additions & 0 deletions example/lib/json_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import 'package:flutter/material.dart';
import 'package:flutter_sdui/src/parser/sdui_json_parser.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';

class JsonExample extends StatelessWidget {
const JsonExample({super.key});

@override
Widget build(BuildContext context) {
// Example JSON data for a simple profile card
final jsonData = {
'type': 'CONTAINER',
'margin': {
'left': 16.0,
'top': 16.0,
'right': 16.0,
'bottom': 16.0
},
'decoration': {
'color': '#FFFFFF',
'borderRadius': {
'radius': 12.0
},
'boxShadow': [
{
'color': '#000000',
'offsetX': 0.0,
'offsetY': 2.0,
'blurRadius': 4.0,
'spreadRadius': 0.0
}
]
},
'child': {
'type': 'COLUMN',
'crossAxisAlignment': 'START',
'children': [
{
'type': 'IMAGE',
'src': 'https://picsum.photos/200',
'width': 200.0,
'height': 200.0,
'fit': 'COVER',
'alignment': 'CENTER'
},
{
'type': 'CONTAINER',
'padding': {
'left': 16.0,
'top': 16.0,
'right': 16.0,
'bottom': 16.0
},
'child': {
'type': 'COLUMN',
'crossAxisAlignment': 'START',
'children': [
{
'type': 'TEXT',
'text': 'John Doe',
'style': {
'color': '#000000',
'fontSize': 24.0,
'fontWeight': 'BOLD'
}
},
{
'type': 'SIZED_BOX',
'height': 8.0
},
{
'type': 'TEXT',
'text': 'Software Developer',
'style': {
'color': '#666666',
'fontSize': 16.0
}
},
{
'type': 'SIZED_BOX',
'height': 16.0
},
{
'type': 'ROW',
'mainAxisAlignment': 'SPACE_BETWEEN',
'children': [
{
'type': 'ICON',
'icon': {
'codePoint': 0xe0b0,
'fontFamily': 'MaterialIcons'
},
'color': '#2196F3',
'size': 24.0
},
{
'type': 'ICON',
'icon': {
'codePoint': 0xe0c8,
'fontFamily': 'MaterialIcons'
},
'color': '#2196F3',
'size': 24.0
},
{
'type': 'ICON',
'icon': {
'codePoint': 0xe0d2,
'fontFamily': 'MaterialIcons'
},
'color': '#2196F3',
'size': 24.0
}
]
}
]
}
}
]
}
};

// Parse the JSON data into a widget
final widget = SduiJsonParser.parse(jsonData);

return MaterialApp(
home: Scaffold(
backgroundColor: Colors.grey[200],
body: Center(
child: widget.toFlutterWidget(),
),
),
);
}
}

// Example of making a JSON request to your backend
Future<Map<String, dynamic>> fetchSduiJson() async {
final response = await http.get(Uri.parse('your-api-endpoint'));
if (response.statusCode == 200) {
return json.decode(response.body);
} else {
throw Exception('Failed to load SDUI JSON');
}
}

class MySduiScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder<Map<String, dynamic>>(
future: fetchSduiJson(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}

if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
}

if (!snapshot.hasData) {
return const Text('No data available');
}

// Parse the JSON data into a widget
final widget = SduiJsonParser.parse(snapshot.data!);

return Scaffold(
body: widget.toFlutterWidget(),
);
},
);
}
}
9 changes: 8 additions & 1 deletion lib/flutter_sdui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
library;

// Export the core parser and widget base
export 'src/parser/sdui_proto_parser.dart'; // New proto parser
export 'src/parser/sdui_proto_parser.dart';
export 'src/widgets/sdui_widget.dart';


// Export individual widget models
export 'src/widgets/sdui_column.dart';
export 'src/widgets/sdui_row.dart';
Expand All @@ -27,3 +28,9 @@ export 'src/generated/sdui.pb.dart';
export 'src/generated/sdui.pbgrpc.dart';
export 'src/generated/sdui.pbenum.dart';
export 'src/generated/sdui.pbjson.dart';

// Export JSON parser and models
export 'src/parser/sdui_json_parser.dart';
export 'src/parser/sdui_json_model.dart';


Loading
Loading