JournalList: Move IconDismissable to its own widget

This commit is contained in:
Vishesh Handa
2019-10-07 19:04:42 +02:00
parent a806013554
commit 1683d4af73
2 changed files with 45 additions and 23 deletions

View 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,
),
),
),
);
}

View File

@ -5,6 +5,7 @@ import 'package:journal/note.dart';
import 'package:journal/state_container.dart';
import 'package:journal/utils.dart';
import 'package:journal/utils/markdown.dart';
import 'package:journal/widgets/icon_dismissable.dart';
import 'package:path/path.dart';
typedef void NoteSelectedFunction(int noteIndex);
@ -48,31 +49,11 @@ class JournalList extends StatelessWidget {
}
var note = notes[i];
return Dismissible(
return IconDismissable(
key: ValueKey("JournalList_" + note.filePath),
child: _buildRow(context, note, i),
background: Container(
color: Colors.red[700],
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,
),
),
),
backgroundColor: Colors.red[800],
iconData: Icons.delete,
onDismissed: (direction) {
final stateContainer = StateContainer.of(context);
stateContainer.removeNote(note);