mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
JournalList: Move IconDismissable to its own widget
This commit is contained in:
41
lib/widgets/icon_dismissable.dart
Normal file
41
lib/widgets/icon_dismissable.dart
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class IconDismissable extends Dismissible {
|
||||||
|
final Color backgroundColor;
|
||||||
|
final IconData iconData;
|
||||||
|
|
||||||
|
IconDismissable({
|
||||||
|
@required Key key,
|
||||||
|
@required this.backgroundColor,
|
||||||
|
@required this.iconData,
|
||||||
|
@required Function onDismissed,
|
||||||
|
@required Widget child,
|
||||||
|
}) : super(
|
||||||
|
key: key,
|
||||||
|
child: child,
|
||||||
|
onDismissed: onDismissed,
|
||||||
|
background: Container(
|
||||||
|
color: backgroundColor,
|
||||||
|
alignment: AlignmentDirectional.centerStart,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(16.0, 0.0, 0.0, 0.0),
|
||||||
|
child: Icon(
|
||||||
|
Icons.delete,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
secondaryBackground: Container(
|
||||||
|
color: backgroundColor,
|
||||||
|
alignment: AlignmentDirectional.centerEnd,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(0.0, 0.0, 16.0, 0.0),
|
||||||
|
child: Icon(
|
||||||
|
Icons.delete,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
@ -5,6 +5,7 @@ import 'package:journal/note.dart';
|
|||||||
import 'package:journal/state_container.dart';
|
import 'package:journal/state_container.dart';
|
||||||
import 'package:journal/utils.dart';
|
import 'package:journal/utils.dart';
|
||||||
import 'package:journal/utils/markdown.dart';
|
import 'package:journal/utils/markdown.dart';
|
||||||
|
import 'package:journal/widgets/icon_dismissable.dart';
|
||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
|
|
||||||
typedef void NoteSelectedFunction(int noteIndex);
|
typedef void NoteSelectedFunction(int noteIndex);
|
||||||
@ -48,31 +49,11 @@ class JournalList extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var note = notes[i];
|
var note = notes[i];
|
||||||
return Dismissible(
|
return IconDismissable(
|
||||||
key: ValueKey("JournalList_" + note.filePath),
|
key: ValueKey("JournalList_" + note.filePath),
|
||||||
child: _buildRow(context, note, i),
|
child: _buildRow(context, note, i),
|
||||||
background: Container(
|
backgroundColor: Colors.red[800],
|
||||||
color: Colors.red[700],
|
iconData: Icons.delete,
|
||||||
alignment: AlignmentDirectional.centerStart,
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.fromLTRB(16.0, 0.0, 0.0, 0.0),
|
|
||||||
child: Icon(
|
|
||||||
Icons.delete,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
secondaryBackground: Container(
|
|
||||||
color: Colors.red[700],
|
|
||||||
alignment: AlignmentDirectional.centerEnd,
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.fromLTRB(0.0, 0.0, 16.0, 0.0),
|
|
||||||
child: Icon(
|
|
||||||
Icons.delete,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onDismissed: (direction) {
|
onDismissed: (direction) {
|
||||||
final stateContainer = StateContainer.of(context);
|
final stateContainer = StateContainer.of(context);
|
||||||
stateContainer.removeNote(note);
|
stateContainer.removeNote(note);
|
||||||
|
Reference in New Issue
Block a user