Skip to content

Commit

Permalink
added clear records functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
luhluh-17 committed May 31, 2020
1 parent 3707f36 commit d135e6a
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 16 deletions.
43 changes: 29 additions & 14 deletions lib/pages/records_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import 'package:neucalcu/models/record.dart';
import 'package:neucalcu/themes/colors.dart';
import 'package:neucalcu/themes/dimensions.dart';
import 'package:neucalcu/widgets/custom_icon_button.dart';
import 'package:neucalcu/widgets/record_container.dart';

class RecordsPage extends StatelessWidget {
static const String id = '/records';

final recordBox = Hive.box<Record>('records');

@override
Widget build(BuildContext context) {
return Material(
Expand Down Expand Up @@ -35,30 +38,42 @@ class RecordsPage extends StatelessWidget {
),
),
Text(
'Settings',
'Record History',
style: TextStyle(
color: Colors.white54,
fontSize: sizeSubHead2,
),
),
Positioned(
right: 0,
child: CustomIconButton(
Icons.delete,
onPressed: () {
recordBox..clear();
Navigator.pop(context);
},
),
),
],
),
Expanded(
child: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: Hive.box<Record>('records').length,
itemBuilder: (context, index) {
final Record record = Hive.box<Record>('records').get(index);
return ListTile(
title: Text(record.answer),
subtitle: Text(record.equation + ' ' + record.date),
);
},
),
),
SizedBox(height: 24.0),
_buildListView(),
],
),
),
);
}

_buildListView() {
return Expanded(
child: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: recordBox.length,
itemBuilder: (context, index) {
final Record record = recordBox.get(index);
return RecordContainer(record: record);
},
),
);
}
}
1 change: 0 additions & 1 deletion lib/providers/calculate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class Calculate with ChangeNotifier {

if (!(_result == 'Answer')) {
Hive.box<Record>('records').add(record);
print('Data: ${Hive.box<Record>('records').length}');
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/themes/shadows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'colors.dart';

const double _radius = 24.0;
const double _blurRadius = 12.0;
const Offset _offset = Offset(2, 2);
const Offset _offset = Offset(4, 4);

ConcaveDecoration getInnerShadow({double radius = _radius}) {
return ConcaveDecoration(
Expand Down
83 changes: 83 additions & 0 deletions lib/widgets/record_container.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import 'package:flutter/material.dart';
import 'package:neucalcu/models/record.dart';
import 'package:neucalcu/themes/colors.dart';
import 'package:neucalcu/themes/dimensions.dart';
import 'package:neucalcu/themes/shadows.dart';

class RecordContainer extends StatefulWidget {
final Record record;

RecordContainer({this.record});

@override
_RecordContainerState createState() => _RecordContainerState();
}

class _RecordContainerState extends State<RecordContainer> {
bool _isPressed = false;

@override
Widget build(BuildContext context) {
return Container(
height: 112.0,
width: double.infinity,
margin: EdgeInsets.symmetric(vertical: 8.0),
child: Listener(
onPointerDown: (event) {
setState(() => _isPressed = true);
},
onPointerUp: (event) {
setState(() => _isPressed = false);
},
child: Stack(
children: <Widget>[
AnimatedContainer(
duration: Duration(milliseconds: 100),
decoration: _isPressed
? getInnerShadow(radius: 16.0)
: getOuterShadow(radius: 16.0),
),
Container(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Row(
children: <Widget>[
Text(
widget.record.date,
style: TextStyle(
color: AppColors.accent,
),
),
],
),
Spacer(),
FittedBox(
fit: BoxFit.fitWidth,
child: Text(
widget.record.answer,
style: TextStyle(
color: AppColors.primaryText,
fontSize: sizeHeadline2,
),
),
),
FittedBox(
fit: BoxFit.fitWidth,
child: Text(
widget.record.equation,
style: TextStyle(
color: AppColors.secondaryText,
),
),
),
],
),
)
],
),
),
);
}
}

0 comments on commit d135e6a

Please sign in to comment.