-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
3,236 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
include: package:flutter_lints/flutter.yaml | ||
|
||
linter: | ||
rules: | ||
library_prefixes: false | ||
analyzer: | ||
errors: | ||
unused_import: false | ||
file_names: false |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
This file is part of KDDockWidgets. | ||
SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
Author: Sérgio Martins <[email protected]> | ||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only | ||
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
import 'dart:io'; | ||
import 'dart:ui'; | ||
|
||
import 'package:KDDockWidgets/models/DockItem.dart'; | ||
import 'package:KDDockWidgets/models/DropArea.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/rendering.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:KDDockWidgets/widgets/DropAreaWidget.dart'; | ||
|
||
Future<Finder?> waitForWidget(WidgetTester tester, Key key, | ||
{int maxTries = 10}) async { | ||
for (int i = 0; i < maxTries; ++i) { | ||
final finder = find.byKey(key); | ||
if (finder.evaluate().isNotEmpty) return finder; | ||
await tester.pump(const Duration(seconds: 1)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
// Returns true when the widget can't be seen anymore | ||
Future<bool> waitForWidgetToHide(WidgetTester tester, Key key, | ||
{int maxTries = 10}) async { | ||
for (int i = 0; i < maxTries; ++i) { | ||
await tester.pump(const Duration(seconds: 1)); | ||
final finder = find.byKey(key); | ||
if (finder.evaluate().isEmpty) return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
Future<void> pumps(WidgetTester tester, int numPumps) async { | ||
for (int i = 0; i < numPumps; ++i) { | ||
await tester.pump(const Duration(seconds: 1)); | ||
} | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
final Widget child; | ||
const MyApp({super.key, required this.child}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
home: RepaintBoundary( | ||
key: const Key('boundary'), | ||
child: Scaffold( | ||
body: child, | ||
), | ||
)); | ||
} | ||
} | ||
|
||
void main() async { | ||
testWidgets('Basic test', (WidgetTester tester) async { | ||
final dock1 = | ||
DockItem(uniqueName: "dw1", guestWidget: Container(color: Colors.cyan)); | ||
final dock2 = | ||
DockItem(uniqueName: "dw2", guestWidget: Container(color: Colors.cyan)); | ||
final dock3 = | ||
DockItem(uniqueName: "dw3", guestWidget: Container(color: Colors.cyan)); | ||
|
||
final dock11 = DockItem( | ||
uniqueName: "dw11", guestWidget: Container(color: Colors.cyan)); | ||
final dock12 = DockItem( | ||
uniqueName: "dw12", guestWidget: Container(color: Colors.cyan)); | ||
final dock13 = DockItem( | ||
uniqueName: "dw13", guestWidget: Container(color: Colors.cyan)); | ||
|
||
final dropArea = DropArea(); | ||
dropArea.addDockItem(dock1, Location.LocationOnTop); | ||
dropArea.addDockItem(dock2, Location.LocationOnBottom); | ||
final group = dropArea.groups.first; | ||
group.addDockWidget(dock3); | ||
group.addDockWidget(dock11); | ||
group.addDockWidget(dock12); | ||
group.addDockWidget(dock13); | ||
|
||
dropArea.setLayoutSize(700, 700); | ||
final dropAreaWidget = DropAreaWidget(dropArea); | ||
|
||
// Build the widget tree | ||
await tester.pumpWidget(MyApp( | ||
child: dropAreaWidget, | ||
)); | ||
|
||
await tester.pump(); | ||
|
||
final renderObject = tester.firstRenderObject(find.byType(RepaintBoundary)); | ||
final image = | ||
await (renderObject as RenderRepaintBoundary).toImage(pixelRatio: 2); | ||
|
||
final byteDataFuture = image.toByteData(format: ImageByteFormat.png); | ||
await tester.pumpAndSettle(); | ||
|
||
final byteData = await byteDataFuture; | ||
final buffer = byteData!.buffer.asUint8List(); | ||
|
||
// Save the bytes to a file | ||
final file = File('screenshot.png'); | ||
file.writeAsBytesSync(buffer); | ||
await tester.pump(); | ||
}); | ||
} |
Oops, something went wrong.