mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-01 04:07:53 +08:00
NoteBrowser: Allow browsing via swipes
This is the first prototype for swiping. It really needs a lot of work, and it needs some kind of animation.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:journal/widgets/swipe_detector.dart';
|
||||
|
||||
import 'note.dart';
|
||||
|
||||
@ -64,7 +65,7 @@ class NoteViewer extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new SingleChildScrollView(
|
||||
var view = new SingleChildScrollView(
|
||||
child: new Column(
|
||||
children: <Widget>[
|
||||
_buildHeader(context),
|
||||
@ -75,6 +76,12 @@ class NoteViewer extends StatelessWidget {
|
||||
),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
);
|
||||
|
||||
return new SwipeDetector(
|
||||
child: view,
|
||||
onLeftSwipe: showNextNoteFunc,
|
||||
onRightSwipe: showPrevNoteFunc,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader(BuildContext context) {
|
||||
|
33
lib/widgets/swipe_detector.dart
Normal file
33
lib/widgets/swipe_detector.dart
Normal file
@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class SwipeDetector extends StatelessWidget {
|
||||
final VoidCallback onLeftSwipe;
|
||||
final VoidCallback onRightSwipe;
|
||||
final Widget child;
|
||||
|
||||
SwipeDetector({
|
||||
@required this.onLeftSwipe,
|
||||
@required this.onRightSwipe,
|
||||
@required this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
double primaryDelta;
|
||||
|
||||
return new GestureDetector(
|
||||
child: child,
|
||||
onHorizontalDragUpdate: (DragUpdateDetails details) {
|
||||
primaryDelta = details.primaryDelta;
|
||||
},
|
||||
onHorizontalDragEnd: (DragEndDetails _) {
|
||||
if (primaryDelta > 0) {
|
||||
onRightSwipe();
|
||||
} else {
|
||||
onLeftSwipe();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user