Skip to content

Commit b60a72c

Browse files
authored
Merge pull request #5 from JothishKamal/dev
feat: v1
2 parents f0c383f + 5566ddd commit b60a72c

25 files changed

+1558
-729
lines changed

.pubignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Files to exclude from pub.dev publishing
2+
3+
SDUI_Flutter_Integration_Guide.txt
4+
docs/
5+
.github/
6+
.hooks/
7+
.idea/
8+
\*.iml
9+
build/
10+
.dart_tool/
11+
bin/

CHANGELOG.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
### Added
66

7-
- Basic framework for Server-Driven UI implementation
8-
- Support for rendering UI from server-provided definitions
9-
- gRPC integration with Protocol Buffers
10-
- Core widget support (Text, Column, Row, Container, etc.)
11-
- Example application demonstrating gRPC usage
12-
- Setup scripts for Protocol Buffer compilation
7+
- Server-Driven UI framework for Flutter
8+
- JSON and gRPC support for dynamic UI rendering
9+
- Protocol Buffers integration for type-safe communication
10+
- Core widget support: Text, Column, Row, Container, Scaffold, Image, Icon, SizedBox, Spacer
11+
- SduiGrpcClient for server communication
12+
- SduiGrpcRenderer widget for rendering server-driven UI
13+
- Comprehensive documentation and examples
14+
- Flutter-to-SDUI conversion utilities
15+
- Error handling and loading states

LICENSE

Lines changed: 140 additions & 251 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,34 @@ This project is licensed under the [LICENSE](LICENSE) file in the repository.
354354
</a>
355355
</p>
356356
</td>
357+
<td>
358+
Rujin Devkota
359+
<p align="center">
360+
<img src = "https://avatars.githubusercontent.com/u/71916379?v=4" width="150" height="150" alt="Rujin Devkota">
361+
</p>
362+
<p align="center">
363+
<a href = "https://github.com/rujin2003">
364+
<img src = "http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg" width="36" height = "36" alt="GitHub"/>
365+
</a>
366+
<a href = "https://www.linkedin.com/in/rujin-devkota/">
367+
<img src = "http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg" width="36" height="36" alt="LinkedIn"/>
368+
</a>
369+
</p>
370+
</td>
371+
<td>
372+
Adhavan K
373+
<p align="center">
374+
<img src = "https://avatars.githubusercontent.com/u/108629544?v=4" width="150" height="150" alt="Adhavan K">
375+
</p>
376+
<p align="center">
377+
<a href = "https://github.com/TBA5854">
378+
<img src = "http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg" width="36" height = "36" alt="GitHub"/>
379+
</a>
380+
<a href = "https://www.linkedin.com/in/adhavan-k-503b8a28a/">
381+
<img src = "http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg" width="36" height="36" alt="LinkedIn"/>
382+
</a>
383+
</p>
384+
</td>
357385
</tr>
358386
</table>
359387

SDUI_Flutter_Integration_Guide.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

example/grpc_example.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_sdui/flutter_sdui.dart';
33

4+
/// Example application demonstrating Flutter SDUI with gRPC.
5+
///
6+
/// This example shows how to:
7+
/// * Connect to a gRPC server
8+
/// * Fetch server-driven UI definitions
9+
/// * Render dynamic UI content
10+
/// * Handle different screen types
411
void main() {
512
runApp(const MyApp());
613
}
714

15+
/// Root application widget that sets up the Material theme and routing.
816
class MyApp extends StatelessWidget {
917
const MyApp({super.key});
1018

@@ -21,6 +29,13 @@ class MyApp extends StatelessWidget {
2129
}
2230
}
2331

32+
/// Demo widget that showcases the gRPC renderer functionality.
33+
///
34+
/// This widget demonstrates how to:
35+
/// * Initialize a gRPC client connection
36+
/// * Switch between different screen definitions
37+
/// * Handle loading and error states
38+
/// * Properly dispose of resources
2439
class GrpcRendererDemo extends StatefulWidget {
2540
const GrpcRendererDemo({super.key});
2641

@@ -35,16 +50,16 @@ class _GrpcRendererDemoState extends State<GrpcRendererDemo> {
3550
@override
3651
void initState() {
3752
super.initState();
38-
// Connect to your gRPC server
53+
// Initialize gRPC client with server connection details
3954
_grpcClient = SduiGrpcClient(
40-
host: 'localhost', // Replace with your server address
41-
port: 50051, // Replace with your server port
55+
host: 'localhost',
56+
port: 50051,
4257
);
4358
}
4459

4560
@override
4661
void dispose() {
47-
// Close the gRPC connection when done
62+
// Clean up gRPC connection
4863
_grpcClient.dispose();
4964
super.dispose();
5065
}
@@ -57,7 +72,7 @@ class _GrpcRendererDemoState extends State<GrpcRendererDemo> {
5772
),
5873
body: Column(
5974
children: [
60-
// Screen selector
75+
// Screen selection controls
6176
Padding(
6277
padding: const EdgeInsets.all(8.0),
6378
child: Row(
@@ -84,7 +99,7 @@ class _GrpcRendererDemoState extends State<GrpcRendererDemo> {
8499
),
85100
),
86101

87-
// SDUI Renderer that fetches UI from gRPC server
102+
// Server-driven UI renderer
88103
Expanded(
89104
child: SduiGrpcRenderer(
90105
client: _grpcClient,

example/grpc_server_example_dart.dart

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,51 @@
1-
// Server implementation example (Dart)
2-
// Note: This is a standalone Dart server, not a Flutter application
3-
// Run with: dart run example/grpc_server_example.dart
1+
/// Example gRPC server implementation for Flutter SDUI.
2+
///
3+
/// This is a standalone Dart server that provides server-driven UI definitions
4+
/// through gRPC. It demonstrates how to:
5+
/// * Set up a gRPC server with SDUI service
6+
/// * Handle different screen requests
7+
/// * Create widget definitions using protobuf
8+
/// * Return complex UI structures
9+
///
10+
/// To run this server:
11+
/// ```bash
12+
/// dart run example/grpc_server_example_dart.dart
13+
/// ```
14+
///
15+
/// The server listens on port 50051 by default.
16+
library;
17+
import 'dart:developer';
18+
419
import 'package:grpc/grpc.dart';
520
import 'package:flutter_sdui/src/generated/sdui.pbgrpc.dart';
621

22+
/// Entry point for the gRPC server.
23+
///
24+
/// Initializes the server with the SDUI service implementation
25+
/// and starts listening for client connections.
726
Future<void> main() async {
827
final server = Server.create(
928
services: [
1029
SduiServiceImpl(),
1130
],
1231
);
1332

14-
final port = 50051;
33+
const port = 50051;
1534
await server.serve(port: port);
16-
print('Server listening on port $port...');
17-
print('Press Ctrl+C to stop');
35+
log('Server listening on port $port...');
36+
log('Press Ctrl+C to stop');
1837
}
1938

20-
// Implementation of the SDUI service
39+
/// Implementation of the SDUI gRPC service.
40+
///
41+
/// This class handles incoming requests for UI definitions and returns
42+
/// appropriate widget data based on the requested screen ID.
2143
class SduiServiceImpl extends SduiServiceBase {
2244
@override
2345
Future<SduiWidgetData> getSduiWidget(
2446
ServiceCall call, SduiRequest request) async {
25-
// Based on the requested screen, return different UI definitions
26-
print('Received request for screen: ${request.screenId}');
47+
log('Received request for screen: ${request.screenId}');
48+
2749
switch (request.screenId) {
2850
case 'home':
2951
return _createHomeScreen();
@@ -32,13 +54,14 @@ class SduiServiceImpl extends SduiServiceBase {
3254
case 'settings':
3355
return _createSettingsScreen();
3456
default:
35-
// Default or error screen
36-
print('Warning: Unknown screen ID requested: ${request.screenId}');
57+
log('Warning: Unknown screen ID requested: ${request.screenId}');
3758
return _createErrorScreen();
3859
}
3960
}
4061

41-
// Sample screen definitions
62+
/// Creates the home screen UI definition.
63+
///
64+
/// Returns a scaffold with an app bar and a column of welcome content.
4265
SduiWidgetData _createHomeScreen() {
4366
final homeScreen = SduiWidgetData()
4467
..type = WidgetType.SCAFFOLD

lib/flutter_sdui.dart

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
1-
/// Flutter SDUI Package
1+
/// Flutter Server-Driven UI Package
22
///
3-
/// A Flutter package to render server driven UI.
3+
/// A Flutter package that enables server-driven UI development by parsing
4+
/// protobuf-based widget definitions from a gRPC server and rendering them
5+
/// as native Flutter widgets.
6+
///
7+
/// This package provides:
8+
/// * Protobuf-based widget parsing and rendering
9+
/// * gRPC client for server communication
10+
/// * A comprehensive set of SDUI widgets that mirror Flutter's core widgets
11+
/// * Type-safe widget definitions through generated protobuf models
12+
///
13+
/// ## Usage
14+
///
15+
/// ```dart
16+
/// // Create a gRPC client
17+
/// final client = SduiGrpcClient(host: 'localhost', port: 50051);
18+
///
19+
/// // Render server-driven UI
20+
/// SduiGrpcRenderer(
21+
/// client: client,
22+
/// screenId: 'home',
23+
/// )
24+
/// ```
425
library;
526

6-
// Export the core parser and widget base
7-
export 'src/parser/sdui_proto_parser.dart'; // New proto parser
27+
// Core parsing and widget foundation
28+
export 'src/parser/sdui_proto_parser.dart';
829
export 'src/widgets/sdui_widget.dart';
930

10-
// Export individual widget models
31+
// SDUI widget implementations
1132
export 'src/widgets/sdui_column.dart';
1233
export 'src/widgets/sdui_row.dart';
1334
export 'src/widgets/sdui_text.dart';
@@ -18,11 +39,11 @@ export 'src/widgets/sdui_scaffold.dart';
1839
export 'src/widgets/sdui_spacer.dart';
1940
export 'src/widgets/sdui_icon.dart';
2041

21-
// Export gRPC client and renderer
42+
// Network communication
2243
export 'src/service/sdui_grpc_client.dart';
2344
export 'src/renderer/sdui_grpc_renderer.dart';
2445

25-
// Export generated Protobuf models for public use
46+
// Generated protobuf models
2647
export 'src/generated/sdui.pb.dart';
2748
export 'src/generated/sdui.pbgrpc.dart';
2849
export 'src/generated/sdui.pbenum.dart';

lib/src/parser/flutter_to_sdui.dart

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ SduiWidget flutterToSdui(Widget widget) {
5050
width: widget.width,
5151
height: widget.height,
5252
fit: widget.fit,
53-
alignment: widget.alignment is Alignment ? widget.alignment as Alignment : null,
53+
alignment: widget.alignment is Alignment
54+
? widget.alignment as Alignment
55+
: null,
5456
repeat: widget.repeat,
5557
color: widget.color,
5658
colorBlendMode: widget.colorBlendMode,
@@ -75,27 +77,40 @@ SduiWidget flutterToSdui(Widget widget) {
7577
} else if (widget is Container) {
7678
return SduiContainer(
7779
child: widget.child != null ? flutterToSdui(widget.child!) : null,
78-
padding: widget.padding is EdgeInsets ? widget.padding as EdgeInsets : null,
80+
padding:
81+
widget.padding is EdgeInsets ? widget.padding as EdgeInsets : null,
7982
margin: widget.margin is EdgeInsets ? widget.margin as EdgeInsets : null,
80-
decoration: widget.decoration is BoxDecoration ? widget.decoration as BoxDecoration : null,
83+
decoration: widget.decoration is BoxDecoration
84+
? widget.decoration as BoxDecoration
85+
: null,
8186
width: null, // Container does not expose width directly
8287
height: null, // Container does not expose height directly
8388
color: widget.color,
84-
alignment: widget.alignment is Alignment ? widget.alignment as Alignment : null,
89+
alignment:
90+
widget.alignment is Alignment ? widget.alignment as Alignment : null,
8591
constraints: widget.constraints,
8692
transform: widget.transform,
87-
transformAlignment: widget.transformAlignment is AlignmentGeometry ? widget.transformAlignment as AlignmentGeometry : null,
93+
transformAlignment: widget.transformAlignment is AlignmentGeometry
94+
? widget.transformAlignment as AlignmentGeometry
95+
: null,
8896
clipBehavior: widget.clipBehavior,
8997
);
9098
} else if (widget is Scaffold) {
9199
return SduiScaffold(
92100
appBar: widget.appBar != null ? flutterToSdui(widget.appBar!) : null,
93101
body: widget.body != null ? flutterToSdui(widget.body!) : null,
94-
floatingActionButton: widget.floatingActionButton != null ? flutterToSdui(widget.floatingActionButton!) : null,
95-
bottomNavigationBar: widget.bottomNavigationBar != null ? flutterToSdui(widget.bottomNavigationBar!) : null,
102+
floatingActionButton: widget.floatingActionButton != null
103+
? flutterToSdui(widget.floatingActionButton!)
104+
: null,
105+
bottomNavigationBar: widget.bottomNavigationBar != null
106+
? flutterToSdui(widget.bottomNavigationBar!)
107+
: null,
96108
drawer: widget.drawer != null ? flutterToSdui(widget.drawer!) : null,
97-
endDrawer: widget.endDrawer != null ? flutterToSdui(widget.endDrawer!) : null,
98-
bottomSheet: widget.bottomSheet != null ? flutterToSdui(widget.bottomSheet!) : null,
109+
endDrawer:
110+
widget.endDrawer != null ? flutterToSdui(widget.endDrawer!) : null,
111+
bottomSheet: widget.bottomSheet != null
112+
? flutterToSdui(widget.bottomSheet!)
113+
: null,
99114
backgroundColor: widget.backgroundColor,
100115
resizeToAvoidBottomInset: widget.resizeToAvoidBottomInset,
101116
primary: widget.primary,
@@ -121,5 +136,6 @@ SduiWidget flutterToSdui(Widget widget) {
121136
shadows: widget.shadows,
122137
);
123138
}
124-
throw UnimplementedError('Conversion for ${widget.runtimeType} is not implemented');
125-
}
139+
throw UnimplementedError(
140+
'Conversion for ${widget.runtimeType} is not implemented');
141+
}

0 commit comments

Comments
 (0)