Skip to content

Commit 9b8e5d4

Browse files
authored
Merge pull request #7 from JothishKamal/dev
feat: migrate to new package name: flutter_glimpse
2 parents 9e426a1 + 2e0c792 commit 9b8e5d4

38 files changed

+3076
-4808
lines changed

.pubignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Files to exclude from pub.dev publishing
22

3-
SDUI_Flutter_Integration_Guide.txt
3+
Glimpse_Flutter_Integration_Guide.txt
44
docs/
55
.github/
66
.hooks/

ADDING_WIDGET.md

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
# Adding a New Widget to the SDUI Package
1+
# Adding a New Widget to the Glimpse Package
22

3-
This guide explains how to add support for a new widget to the Flutter SDUI package, including JSON and proto (gRPC) support. The process ensures your widget can be described by the server, parsed on the client, and rendered as a real Flutter widget.
3+
This guide explains how to add support for a new widget to the Flutter Glimpse package, including JSON and proto (gRPC) support. The process ensures your widget can be described by the server, parsed on the client, and rendered as a real Flutter widget.
44

55
---
66

7-
## 1. Create the SDUI Widget Class
7+
## 1. Create the Glimpse Widget Class
88

99
- **Where:** `lib/src/widgets/`
10-
- **What:** Create a Dart class (e.g., `SduiMyWidget`) that extends `SduiWidget`.
11-
- **Why:** This class acts as the runtime representation of your widget in the SDUI system. It bridges the data-driven world (JSON/proto) and the actual Flutter widget tree.
12-
- **How:**
10+
- **What:** Create a Dart class (e.g., `GlimpseMyWidget`) that extends `GlimpseWidget`.
11+
- **Why:** This class acts as the runtime representation of your widget in the Glimpse system. It bridges the data-driven world (JSON/proto) and the actual Flutter widget tree.
12+
- **How:**
1313
- Add all properties your widget needs (e.g., text, color, children).
14-
- Implement the `toFlutterWidget()` method to convert your SDUI widget to a real Flutter widget.
14+
- Implement the `toFlutterWidget()` method to convert your Glimpse widget to a real Flutter widget.
1515
- If your widget has children, make sure to recursively call `toFlutterWidget()` on them.
1616

1717
**Example:**
18+
1819
```dart
1920
import 'package:flutter/widgets.dart';
20-
import 'sdui_widget.dart';
21+
import 'glimpse_widget.dart';
2122
22-
class SduiMyWidget extends SduiWidget {
23+
class GlimpseMyWidget extends GlimpseWidget {
2324
final String title;
2425
final Color? color;
25-
final List<SduiWidget> children;
26+
final List<GlimpseWidget> children;
2627
// Add other properties as needed
2728
28-
SduiMyWidget({
29+
GlimpseMyWidget({
2930
required this.title,
3031
this.color,
3132
this.children = const [],
@@ -41,27 +42,29 @@ class SduiMyWidget extends SduiWidget {
4142
}
4243
}
4344
```
44-
*Tip: Look at existing SDUI widgets for structure and naming conventions. Try to keep your API as close as possible to the real Flutter widget for familiarity.*
45+
46+
_Tip: Look at existing Glimpse widgets for structure and naming conventions. Try to keep your API as close as possible to the real Flutter widget for familiarity._
4547

4648
---
4749

4850
## 2. Update the Parser(s)
4951

5052
### a. JSON Parsing
5153

52-
- **Where:** `lib/src/parser/sdui_proto_parser.dart`
54+
- **Where:** `lib/src/parser/glimpse_proto_parser.dart`
5355
- **What:** Add logic to parse your widget from JSON and serialize it back.
54-
- **Why:** This allows the SDUI system to construct your widget from server-provided JSON, and to serialize it back for debugging or round-tripping.
56+
- **Why:** This allows the Glimpse system to construct your widget from server-provided JSON, and to serialize it back for debugging or round-tripping.
5557
- **How:**
5658
- Add a case for your widget in the `parseJSON` method (e.g., `case 'my_widget': return _parseJsonMyWidget(data);`).
57-
- Implement a `_parseJsonMyWidget(Map<String, dynamic> data)` method to extract all properties from the JSON map and construct your SDUI widget.
58-
- Update the `toJson` and `_toJsonMyWidget` methods to support serialization (convert your SDUI widget back to a JSON map).
59+
- Implement a `_parseJsonMyWidget(Map<String, dynamic> data)` method to extract all properties from the JSON map and construct your Glimpse widget.
60+
- Update the `toJson` and `_toJsonMyWidget` methods to support serialization (convert your Glimpse widget back to a JSON map).
5961
- If your widget has enums or complex types, add helper methods for parsing/serializing them.
6062

6163
**Example:**
64+
6265
```dart
63-
static SduiMyWidget _parseJsonMyWidget(Map<String, dynamic> data) {
64-
return SduiMyWidget(
66+
static GlimpseMyWidget _parseJsonMyWidget(Map<String, dynamic> data) {
67+
return GlimpseMyWidget(
6568
title: data['title'] ?? '',
6669
color: _parseJsonColor(data['color']),
6770
children: (data['children'] as List<dynamic>? ?? [])
@@ -73,68 +76,71 @@ static SduiMyWidget _parseJsonMyWidget(Map<String, dynamic> data) {
7376

7477
### b. Proto Parsing
7578

76-
- **Where:** `lib/src/parser/sdui_proto_parser.dart`
79+
- **Where:** `lib/src/parser/glimpse_proto_parser.dart`
7780
- **What:** Add logic to parse your widget from proto and serialize it back.
78-
- **Why:** This allows the SDUI system to construct your widget from gRPC/proto data, and to serialize it back for server communication or round-tripping.
81+
- **Why:** This allows the Glimpse system to construct your widget from gRPC/proto data, and to serialize it back for server communication or round-tripping.
7982
- **How:**
8083
- Add a case for your widget in the `parseProto` and `fromProto` methods.
81-
- Implement `_parseProtoMyWidget(SduiWidgetData data)` and `myWidgetFromProto` to extract all properties from the proto message and construct your SDUI widget.
82-
- Add `myWidgetToProto` for proto serialization (convert your SDUI widget to a proto message).
84+
- Implement `_parseProtoMyWidget(GlimpseWidgetData data)` and `myWidgetFromProto` to extract all properties from the proto message and construct your Glimpse widget.
85+
- Add `myWidgetToProto` for proto serialization (convert your Glimpse widget to a proto message).
8386
- Use helper methods for enums, colors, and nested children as needed.
8487

8588
**Example:**
89+
8690
```dart
87-
static SduiMyWidget myWidgetFromProto(SduiWidgetData data) {
88-
return SduiMyWidget(
91+
static GlimpseMyWidget myWidgetFromProto(GlimpseWidgetData data) {
92+
return GlimpseMyWidget(
8993
title: data.stringAttributes['title'] ?? '',
9094
color: data.hasColor() ? _parseProtoColor(data.color) : null,
91-
children: data.children.map((c) => SduiParser.parseProto(c)).toList(),
95+
children: data.children.map((c) => GlimpseParser.parseProto(c)).toList(),
9296
);
9397
}
9498
```
9599

96-
*Tip: Use the helpers and patterns from other widgets to handle enums, colors, and nested children. Consistency makes the codebase easier to maintain.*
100+
_Tip: Use the helpers and patterns from other widgets to handle enums, colors, and nested children. Consistency makes the codebase easier to maintain._
97101

98102
---
99103

100104
## 3. Update the Widget Type Enum
101105

102-
- **Where:** `sdui.proto` (your proto definitions)
106+
- **Where:** `glimpse.proto` (your proto definitions)
103107
- **What:** Add your widget to the `WidgetType` enum.
104108
- **Why:** This allows the server and client to communicate about your new widget type in a type-safe way.
105-
- **How:**
109+
- **How:**
106110
- Add a new value (e.g., `MY_WIDGET`) to the `WidgetType` enum in your proto file.
107111
- Regenerate Dart code from your proto files (see README for instructions, usually a script in `tool/`).
108112

109113
**Example:**
114+
110115
```protobuf
111116
enum WidgetType {
112117
// ... existing types ...
113118
MY_WIDGET = 42;
114119
}
115120
```
116121

117-
*Tip: Make sure the enum value is unique and does not conflict with existing types.*
122+
_Tip: Make sure the enum value is unique and does not conflict with existing types._
118123

119124
---
120125

121-
## 4. Add to Flutter-to-SDUI Converter
126+
## 4. Add to Flutter-to-Glimpse Converter
122127

123-
- **Where:** `lib/src/parser/flutter_to_sdui.dart`
124-
- **What:** Add a case to convert a real Flutter widget to your SDUI widget.
125-
- **Why:** This enables tools and tests to convert existing Flutter code to SDUI format, and helps with migration or round-trip testing.
126-
- **How:**
128+
- **Where:** `lib/src/parser/flutter_to_glimpse.dart`
129+
- **What:** Add a case to convert a real Flutter widget to your Glimpse widget.
130+
- **Why:** This enables tools and tests to convert existing Flutter code to Glimpse format, and helps with migration or round-trip testing.
131+
- **How:**
127132
- Add an `else if` block for your widget type.
128-
- Map all relevant properties from the Flutter widget to your SDUI widget.
133+
- Map all relevant properties from the Flutter widget to your Glimpse widget.
129134
- If your widget is not supported for conversion, throw an `UnimplementedError` with a clear message.
130135

131136
**Example:**
137+
132138
```dart
133139
else if (widget is MyWidget) {
134-
return SduiMyWidget(
140+
return GlimpseMyWidget(
135141
title: widget.title,
136142
color: widget.color,
137-
children: widget.children.map(flutterToSdui).toList(),
143+
children: widget.children.map(flutterToGlimpse).toList(),
138144
);
139145
}
140146
```
@@ -147,11 +153,11 @@ else if (widget is MyWidget) {
147153
- **Why:** Testing catches bugs early and ensures your widget behaves as expected in all supported formats.
148154
- **How:**
149155
- Add unit tests for JSON and proto parsing/serialization.
150-
- Add tests for Flutter-to-SDUI conversion.
156+
- Add tests for Flutter-to-Glimpse conversion.
151157
- Create sample JSON and proto definitions for your widget and verify they render correctly in a demo app or test harness.
152158
- Test edge cases (missing properties, nulls, invalid values).
153159

154-
*Tip: Use the sample files and test cases for existing widgets as a template. Automated tests are preferred, but manual testing in a demo app is also valuable.*
160+
_Tip: Use the sample files and test cases for existing widgets as a template. Automated tests are preferred, but manual testing in a demo app is also valuable._
155161

156162
---
157163

@@ -169,24 +175,25 @@ else if (widget is MyWidget) {
169175
## Example Checklist
170176

171177
- [ ] Widget class in `lib/src/widgets/`
172-
- [ ] JSON parse/serialize in `sdui_proto_parser.dart`
173-
- [ ] Proto parse/serialize in `sdui_proto_parser.dart`
178+
- [ ] JSON parse/serialize in `glimpse_proto_parser.dart`
179+
- [ ] Proto parse/serialize in `glimpse_proto_parser.dart`
174180
- [ ] Enum in proto and regenerated Dart code
175-
- [ ] Flutter-to-SDUI conversion
181+
- [ ] Flutter-to-Glimpse conversion
176182
- [ ] Tests and sample data
177183
- [ ] Documentation
178184

179185
---
180186

181187
**Tips & Best Practices:**
188+
182189
- Follow the structure and naming conventions of existing widgets for consistency.
183190
- Keep your widget’s API as close as possible to the real Flutter widget for familiarity.
184-
- Only map properties that are supported by both SDUI and the underlying Flutter widget.
191+
- Only map properties that are supported by both Glimpse and the underlying Flutter widget.
185192
- If your widget has complex properties (e.g., enums, nested objects), add helper methods for parsing/serialization.
186193
- If you’re unsure, look at how similar widgets are implemented in the codebase.
187194
- Use clear error messages for unsupported or unimplemented features.
188195
- Test with both minimal and maximal property sets.
189196

190197
---
191198

192-
If you have questions, check the code for similar widgets or open an issue!
199+
If you have questions, check the code for similar widgets or open an issue!

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
- JSON and gRPC support for dynamic UI rendering
99
- Protocol Buffers integration for type-safe communication
1010
- 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
11+
- GlimpseGrpcClient for server communication
12+
- GlimpseGrpcRenderer widget for rendering server-driven UI
1313
- Comprehensive documentation and examples
14-
- Flutter-to-SDUI conversion utilities
14+
- Flutter-to-Glimpse conversion utilities
1515
- Error handling and loading states

0 commit comments

Comments
 (0)