Skip to content

Commit

Permalink
[+] Migrated to Dart 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rvachev committed Jul 20, 2023
1 parent ba65f21 commit a8f9d51
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"fluttertoast","path":"/Users/romanrvachev/.pub-cache/hosted/pub.dev/fluttertoast-8.2.1/","native_build":true,"dependencies":[]}],"android":[{"name":"fluttertoast","path":"/Users/romanrvachev/.pub-cache/hosted/pub.dev/fluttertoast-8.2.1/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"fluttertoast","path":"/Users/romanrvachev/.pub-cache/hosted/pub.dev/fluttertoast-8.2.1/","dependencies":[]}]},"dependencyGraph":[{"name":"fluttertoast","dependencies":[]}],"date_created":"2023-03-13 15:40:41.852305","version":"3.7.7"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"fluttertoast","path":"/Users/romanrvachev/.pub-cache/hosted/pub.dev/fluttertoast-8.2.1/","native_build":true,"dependencies":[]}],"android":[{"name":"fluttertoast","path":"/Users/romanrvachev/.pub-cache/hosted/pub.dev/fluttertoast-8.2.1/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"fluttertoast","path":"/Users/romanrvachev/.pub-cache/hosted/pub.dev/fluttertoast-8.2.1/","dependencies":[]}]},"dependencyGraph":[{"name":"fluttertoast","dependencies":[]}],"date_created":"2023-07-20 13:21:03.555486","version":"3.10.5"}
86 changes: 63 additions & 23 deletions lib/src/debug_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import 'package:flutter/material.dart';
import 'logs/debug_log.dart';
import 'network/environment/models/environment_item.dart';

enum OpenGestureAlignment {
topLeft(alignment: Alignment.topLeft),
topCenter(alignment: Alignment.topCenter),
topRight(alignment: Alignment.topRight);

const OpenGestureAlignment({required this.alignment});

final Alignment alignment;
}

class DebugPanel extends StatefulWidget {
/// Selected [EnvironmentItem] which is used for displaying current item in dropdown
final EnvironmentItem? selectedEnvironment;
Expand All @@ -25,16 +35,22 @@ class DebugPanel extends StatefulWidget {
/// A widget which displayed below [EnvironmentDropdown] and "View logs" button
final Widget? additionalItem;

/// An aligment for start gesture position
/// May be only on the top of the screen
final OpenGestureAlignment openGestureAlignment;

/// child (usually whole app) to place debug panel on the screen
final Widget child;

const DebugPanel(
{super.key,
this.selectedEnvironment,
this.environments = const [],
this.onEnvironmentChanged,
this.additionalItem,
required this.child});
const DebugPanel({
super.key,
this.selectedEnvironment,
this.environments = const [],
this.onEnvironmentChanged,
this.additionalItem,
this.openGestureAlignment = OpenGestureAlignment.topLeft,
required this.child,
});

@override
State<DebugPanel> createState() => _DebugPanelState();
Expand Down Expand Up @@ -96,14 +112,17 @@ class _DebugPanelState extends State<DebugPanel> {
key: _scaffoldKey,
children: [
widget.child,
Positioned(
right: 16,
Align(
alignment: widget.openGestureAlignment.alignment,
child: SafeArea(
child: SizedBox(
height: 50,
width: 50,
child: DrawerGestureDetector(
callback: _showDebugPanel,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: SizedBox(
height: 50,
width: 50,
child: DrawerGestureDetector(
callback: _showDebugPanel,
),
),
),
),
Expand All @@ -116,23 +135,44 @@ class _DebugPanelState extends State<DebugPanel> {
}

void _showLogsDialog() async {
if (_navigatorKey.currentContext == null) return;
if (_scaffoldKey.currentContext == null) return;
final logs = LogRecordsContainer.instance.logs
.map((LogMessage log) =>
DebugLog(message: log.toString(), type: log.type.toLogType()))
.toList();
final incomingLogs = DebugMenuLogContainer.messages;
logs.addAll(incomingLogs);
showDialog(
context: _navigatorKey.currentContext!,
context: _scaffoldKey.currentContext!,
barrierDismissible: false,
builder: (context) {
return Dialog(
insetPadding: const EdgeInsets.all(20.0),
child: Container(
color: Colors.white,
child: LogsListView(
logs: logs,
)),
return WillPopScope(
onWillPop: () async {
Navigator.of(context).pop();
return false;
},
child: Dialog(
insetPadding: const EdgeInsets.all(20.0),
child: Container(
color: Colors.white,
child: Stack(
children: [
LogsListView(
logs: logs,
),
Positioned(
bottom: 0,
left: 0,
child: TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Закрыть'),
),
)
],
)),
),
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/logs/debug_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class DebugLog {
final Object message;
final LogType type;

DebugLog({required this.message, required this.type});
const DebugLog({required this.message, required this.type});
}
18 changes: 13 additions & 5 deletions lib/src/ui/drawer_gesture_detector.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

class DrawerGestureDetector extends StatelessWidget {
Expand All @@ -7,11 +8,18 @@ class DrawerGestureDetector extends StatelessWidget {

@override
Widget build(BuildContext context) {
return GestureDetector(
onLongPressMoveUpdate: (details) {
if (details.offsetFromOrigin.dy > 70) {
callback();
}
return RawGestureDetector(
gestures: {
LongPressGestureRecognizer:
GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>(
() => LongPressGestureRecognizer(),
(LongPressGestureRecognizer instance) {
instance.onLongPressMoveUpdate = (details) {
if (details.offsetFromOrigin.dy > 70) {
callback();
}
};
}),
},
);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/ui/logs_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class LogsListView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView.separated(
reverse: true,
itemCount: logs.length,
itemBuilder: (context, i) {
return _LogItem(log: logs[i]);
Expand All @@ -34,7 +33,7 @@ class _LogItem extends StatelessWidget {
return Material(
child: InkWell(
onLongPress: () async {
await Clipboard.setData(ClipboardData(text: log.toString()));
await Clipboard.setData(ClipboardData(text: log.message.toString()));
Fluttertoast.showToast(
msg: 'Log has been copied to clipboard',
toastLength: Toast.LENGTH_LONG,
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
name: effective_debug_menu
description: A new Flutter package project.
version: 0.0.5
version: 1.0.0
homepage: "none"
publish_to: "none"

environment:
sdk: ">=2.18.5 <3.0.0"
sdk: ">=3.0.0 <4.0.0"
flutter: ">=1.17.0"

dependencies:
flutter:
sdk: flutter
dio: ^4.0.6
dio: ^5.3.0
fluttertoast: ^8.2.1
effective_dio_interceptor:
git:
url: https://github.com/rvachev/effective_dio_interceptor
version: ^0.0.2
version: ^1.0.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit a8f9d51

Please sign in to comment.