Skip to content

Commit

Permalink
Tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
fujidaiti committed May 23, 2024
1 parent 83306f8 commit 7f050a6
Show file tree
Hide file tree
Showing 12 changed files with 346 additions and 210 deletions.
41 changes: 24 additions & 17 deletions cookbook/lib/showcase/todo_list/todo_editor.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:cookbook/showcase/todo_list/models.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -40,23 +42,28 @@ class _TodoEditorState extends State<TodoEditor> {
return true;
}

// Show a confirmation dialog.
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Discard changes?'),
actions: [
TextButton(
onPressed: () =>
Navigator.popUntil(context, (route) => route.isFirst),
child: const Text('Discard'),
),
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
],
Future.delayed(
const Duration(milliseconds: 500),
() {
// Show a confirmation dialog.
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Discard changes?'),
actions: [
TextButton(
onPressed: () =>
Navigator.popUntil(context, (route) => route.isFirst),
child: const Text('Discard'),
),
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
],
);
},
);
},
);
Expand Down
16 changes: 14 additions & 2 deletions cookbook/lib/tutorial/imperative_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class _ExampleSheet extends StatelessWidget {
// or false otherwise. This is useful when, for example, you want to
// show a confirmation dialog before dismissing the sheet.
onDismiss: () {
showConfirmDialog(context);
return false;
// showConfirmDialog(context);
// return false;
return true;
},
child: DraggableSheet(
child: Card(
Expand All @@ -69,6 +70,17 @@ class _ExampleSheet extends StatelessWidget {
height: 500,
width: double.infinity,
),
// child: SizedBox(
// height: 500,
// child: ListView.builder(
// itemCount: 20,
// itemBuilder: (context, index) {
// return ListTile(
// title: Text('Item $index'),
// );
// },
// ),
// ),
),
),
);
Expand Down
11 changes: 1 addition & 10 deletions package/lib/src/draggable/sheet_draggable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';

import '../foundation/sheet_drag.dart';
import '../foundation/sheet_extent.dart';
import '../scrollable/scrollable_sheet.dart';
import 'draggable_sheet.dart';
Expand Down Expand Up @@ -63,15 +62,7 @@ class _SheetDraggableState extends State<SheetDraggable> {

void _handleDragStart(DragStartDetails details) {
assert(_currentDrag == null);
_currentDrag = _extent?.drag(
SheetDragStartDetails(
sourceTimeStamp: details.sourceTimeStamp,
globalPosition: details.globalPosition,
localPosition: details.localPosition,
kind: details.kind,
),
_disposeDrag,
);
_currentDrag = _extent?.drag(details, _disposeDrag);
}

void _handleDragUpdate(DragUpdateDetails details) {
Expand Down
59 changes: 50 additions & 9 deletions package/lib/src/foundation/sheet_activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ import 'sheet_status.dart';
@internal
@optionalTypeArgs
abstract class SheetActivity<T extends SheetExtent> {
bool _disposed = false;
bool get disposed {
assert(!_mounted || !_disposed);
return _disposed;
}

bool _mounted = false;
bool get mounted => _mounted;
bool get mounted {
assert(!_mounted || !_disposed);
return _mounted;
}

T? _owner;
T get owner {
Expand All @@ -26,10 +35,9 @@ abstract class SheetActivity<T extends SheetExtent> {

@mustCallSuper
void init(T owner) {
assert(
_owner == null,
'init() must be called only once.',
);
assert(_owner == null);
assert(!_mounted);
assert(!_disposed);

_owner = owner;
_mounted = true;
Expand All @@ -42,6 +50,7 @@ abstract class SheetActivity<T extends SheetExtent> {

void dispose() {
_mounted = false;
_disposed = true;
}

bool isCompatibleWith(SheetExtent newOwner) => newOwner is T;
Expand Down Expand Up @@ -102,6 +111,20 @@ abstract class SheetActivity<T extends SheetExtent> {
}());
return true;
}

@protected
bool debugAssertNotDisposed() {
assert(() {
if (disposed) {
throw FlutterError(
'A $runtimeType was used after being disposed. Once you have '
'called dispose() on a $runtimeType, it can no longer be used.',
);
}
return true;
}());
return true;
}
}

@internal
Expand Down Expand Up @@ -170,14 +193,32 @@ class IdleSheetActivity extends SheetActivity {
@internal
class DragSheetActivity extends SheetActivity
with UserControlledSheetActivityMixin
implements SheetDragControllerDelegate {
implements SheetDragControllerTarget {
DragSheetActivity();

@override
AxisDirection get dragAxisDirection => AxisDirection.up;
VerticalDirection get dragAxisDirection => VerticalDirection.up;

@override
Offset computeMinPotentialDeltaConsumption(Offset delta) {
final metrics = owner.metrics;

switch (delta.dy) {
case > 0:
final draggableDistance = max(0.0, metrics.maxPixels - metrics.pixels);
return Offset(delta.dx, min(draggableDistance, delta.dy));

case < 0:
final draggableDistance = max(0.0, metrics.minPixels - metrics.pixels);
return Offset(delta.dx, max(-1 * draggableDistance, delta.dy));

case _:
return delta;
}
}

@override
void onDragUpdate(SheetDragUpdateDetails details) {
void applyUserDragUpdate(SheetDragUpdateDetails details) {
final physicsAppliedDelta = owner.config.physics
.applyPhysicsToOffset(details.primaryDelta, owner.metrics);
if (physicsAppliedDelta != 0) {
Expand All @@ -186,7 +227,7 @@ class DragSheetActivity extends SheetActivity
}

@override
void onDragEnd(SheetDragEndDetails details) {
void applyUserDragEnd(SheetDragEndDetails details) {
owner.goBallistic(details.primaryVelocity);
}
}
Expand Down
Loading

0 comments on commit 7f050a6

Please sign in to comment.