Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/active cell wrapper #27

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ ios/.generated/
.project
.settings
.vscode
pubspec.lock
pubspec.lock
.metadata
10 changes: 9 additions & 1 deletion packages/swayze/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# 1.2.0

- Adds drag and fill support. When enabled on the `SwayzeConfig`, applications can then react to
`FillIntoTargetIntent` and `FillIntoUnknownIntent`.
- Deprecates `id` property on `UserSelectionModel`.
- Allow resizing of columns or rows.
- Add drag and drop for columns and rows.

# 1.1.0

- Bump `swayze_math` from 1.0.0 to 1.1.0

# 1.0.3

- Fix `SwayzeSliverTable` using `Navigator`'s `overlay` property instead of fetching the closest
- Fix `SwayzeSliverTable` using `Navigator`'s `overlay` property instead of fetching the closest
`Overlay` ancestor.

# 1.0.2
Expand Down
6 changes: 6 additions & 0 deletions packages/swayze/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ final myStyle = SwayzeStyle.defaultSwayzeStyle.copyWith(
selectionStyle: SelectionStyle(color: Colors.pink),
);
```


### Example

Take a look at [example/lib/main.dart](example/lib/main.dart) for a working example.

54 changes: 54 additions & 0 deletions packages/swayze/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

/macos
/android
/ios
/windows
/linux
/web
/test
3 changes: 3 additions & 0 deletions packages/swayze/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Swayze Example

A testbed for swayze.
1 change: 1 addition & 0 deletions packages/swayze/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:rows_lint/analysis_options.yaml
193 changes: 193 additions & 0 deletions packages/swayze/example/lib/backend/fake_cells_backend.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
import 'dart:convert';

final map = <int, String>{
0: '''
[
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-0-0",
"position":{ "x":0, "y":0 },
"value":"Bold",
"type":"TEXT",
"style":{
"isBold":true
}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-0-1",
"position":{ "x":0, "y":1 },
"value":"Italic",
"type":"TEXT",
"style":{
"isItalic":true
}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-0-2",
"position":{ "x":0, "y":2 },
"value":"Underline",
"type":"TEXT",
"style":{
"isUnderline":true
}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-0-3",
"position":{ "x":0, "y":3 },
"value":"Background color",
"type":"TEXT",
"style":{
"fontColor":"#2c2c2c",
"backgroundColor":"#ab5cb3"
}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-1-0",
"position":{ "x":1, "y":0 },
"value":"Align left",
"type":"TEXT",
"style":{
"alignment":"LEFT"
}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-1-1",
"position":{ "x":1, "y":1 },
"value":"Align right",
"type":"TEXT",
"style":{
"alignment":"RIGHT"
}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-1-2",
"position":{ "x":1, "y":2 },
"value":"Align center",
"type":"TEXT",
"style":{
"alignment":"CENTER"
}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-1-3",
"position":{ "x":1, "y":3 },
"value":"Align left Align left Align left Align left Align left",
"type":"TEXT",
"style":{
"alignment":"LEFT"
}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-1-4",
"position":{ "x":1, "y":4 },
"value":"Align right Align right Align right Align right",
"type":"TEXT",
"style":{
"alignment":"RIGHT"
}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-1-5",
"position":{ "x":1, "y":5 },
"value":"Align center Align center Align center Align center Align center Align center ",
"type":"TEXT",
"style":{
"alignment":"CENTER"
}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-2-0",
"position":{ "x":2, "y":0 },
"value":"✅ ",
"type":"TEXT",
"style":{

}
},
{
"id":"b49a32df-3605-4397-9984-d7ab62afd143-2-1",
"position":{ "x":2, "y":1 },
"value":"❌",
"type":"TEXT",
"style":{
"alignment":"RIGHT"
}
}
]''',
1: '''
[
{
"id":"2b45b403-caf9-4fb5-83b7-0dae2b7f6228-0-0",
"position":{ "x":0, "y":0 },
"value":"Red",
"type":"TEXT",
"style":{
"backgroundColor":"#D12229",
"fontColor": "#FFFFFF"
}
},
{
"id":"2b45b403-caf9-4fb5-83b7-0dae2b7f6228-0-1",
"position":{ "x":0, "y":1 },
"value":"Orange",
"type":"TEXT",
"style":{
"backgroundColor":"#F68A1E",
"fontColor": "#FFFFFF"
}
},
{
"id":"2b45b403-caf9-4fb5-83b7-0dae2b7f6228-0-2",
"position":{ "x":0, "y":2 },
"value":"Yellow",
"type":"TEXT",
"style":{
"isBold":false,
"backgroundColor":"#FDE01A",
"fontColor": "#FFFFFF"
}
},
{
"id":"2b45b403-caf9-4fb5-83b7-0dae2b7f6228-0-3",
"position":{ "x":0, "y":3 },
"value":"Green",
"type":"TEXT",
"style":{
"isBold":false,
"backgroundColor":"#007940",
"fontColor": "#FFFFFF"
}
},
{
"id":"2b45b403-caf9-4fb5-83b7-0dae2b7f6228-0-3",
"position":{ "x":0, "y":4 },
"value":"Indigo",
"type":"TEXT",
"style":{
"isBold":false,
"backgroundColor":"#24408E",
"fontColor": "#FFFFFF"
}
},
{
"id":"2b45b403-caf9-4fb5-83b7-0dae2b7f6228-0-3",
"position":{ "x":0, "y":5 },
"value":"Violet",
"type":"TEXT",
"style":{
"isBold":false,
"backgroundColor":"#732982",
"fontColor": "#FFFFFF"
}
}
]
''',
};

const decoder = JsonDecoder();

/// Don't take this function seriously
List<dynamic> getCellsData(int index) {
final data = map[index]!;
final dynamic dec = decoder.convert(data);
return dec as List<dynamic>;
}
32 changes: 32 additions & 0 deletions packages/swayze/example/lib/backend/fake_table_backend.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'dart:convert';

final map = <int, String>{
0: '''
{
"id":"274d2509-a651-49d8-88b0-e72e0aaa63b3",
"name":"Styles",
"columns":6,
"rows":6,
"columnStyles":[{"position":1,"size":162,"__typename":"DimensionStyle"},{"position":4,"size":283,"__typename":"DimensionStyle"}],
"rowStyles":[]
}''',
1: '''
{
"id":"26163cb0-7c0e-11eb-b54b-d161845548b6",
"name":"Longer table",
"index":1,
"columns":36,
"rows":1060,
"columnStyles":[{"position":0,"size":167,"__typename":"DimensionStyle"}],
"rowStyles":[{"position":190,"size":54,"hidden":false,"__typename":"DimensionStyle"}]
}''',
};

const decoder = JsonDecoder();

/// Don't take this function seriously
Map<String, dynamic> getTableData(int index) {
final data = map[index]!;
final dynamic dec = decoder.convert(data);
return dec as Map<String, dynamic>;
}
66 changes: 66 additions & 0 deletions packages/swayze/example/lib/cell_editor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:swayze_math/swayze_math.dart';

import 'data/my_cells_controller.dart';

class CellEditor extends StatefulWidget {
final MyCellsController cellsController;
final IntVector2 cellCoordinate;
final VoidCallback close;
final BuildContext originContext;

const CellEditor({
Key? key,
required this.cellCoordinate,
required this.close,
required this.cellsController,
required this.originContext,
}) : super(key: key);

@override
State<CellEditor> createState() => _CellEditorState();
}

class _CellEditorState extends State<CellEditor> {
late final cell =
widget.cellsController.cellMatrixReadOnly[widget.cellCoordinate];

late final TextEditingController textController = TextEditingController(
text: cell?.value ?? '',
);
late final FocusNode focusNode = FocusNode(
debugLabel: 'CellEditor',
)..requestFocus();

@override
void initState() {
super.initState();
focusNode.addListener(checkFocus);
}

@override
void dispose() {
focusNode.removeListener(checkFocus);
super.dispose();
}

void checkFocus() {
if (!focusNode.hasFocus) {
widget.close();
}
}

@override
Widget build(BuildContext context) {
return IntrinsicWidth(
child: EditableText(
onSubmitted: (value) {},
controller: textController,
focusNode: focusNode,
cursorColor: Colors.black,
backgroundCursorColor: Colors.grey.shade200,
style: DefaultTextStyle.of(context).style,
),
);
}
}
Loading