Last active
May 3, 2019 10:35
-
-
Save jayjonas1996/56696eadf49548bf4452fd087418701b to your computer and use it in GitHub Desktop.
Widget for the tile in the staggered view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:auto_size_text/auto_size_text.dart'; | |
import '../ViewControllers/NotePage.dart'; | |
import '../Models/Note.dart'; | |
import '../Models/Utility.dart'; | |
class MyStaggeredTile extends StatefulWidget { | |
final Note note; | |
MyStaggeredTile(this.note); | |
@override | |
_MyStaggeredTileState createState() => _MyStaggeredTileState(); | |
} | |
class _MyStaggeredTileState extends State<MyStaggeredTile> { | |
String _content ; | |
double _fontSize ; | |
Color tileColor ; | |
String title; | |
@override | |
Widget build(BuildContext context) { | |
_content = widget.note.content; | |
_fontSize = _determineFontSizeForContent(); | |
tileColor = widget.note.note_color; | |
title = widget.note.title; | |
return GestureDetector( | |
onTap: ()=> _noteTapped(context), | |
child: Container( | |
decoration: BoxDecoration( | |
border: tileColor == Colors.white ? Border.all(color: CentralStation.borderColor) : null, | |
color: tileColor, | |
borderRadius: BorderRadius.all(Radius.circular(8))), | |
padding: EdgeInsets.all(8), | |
child: constructChild(),) , | |
); | |
} | |
void _noteTapped(BuildContext ctx) { | |
CentralStation.updateNeeded = false; | |
Navigator.push(ctx, MaterialPageRoute(builder: (ctx) => NotePage(widget.note))); | |
} | |
Widget constructChild() { | |
List<Widget> contentsOfTiles = []; | |
if(widget.note.title.length != 0) { | |
contentsOfTiles.add( | |
AutoSizeText(title, | |
style: TextStyle(fontSize: _fontSize,fontWeight: FontWeight.bold), | |
maxLines: widget.note.title.length == 0 ? 1 : 3, | |
textScaleFactor: 1.5, | |
), | |
); | |
contentsOfTiles.add(Divider(color: Colors.transparent,height: 6,),); | |
} | |
contentsOfTiles.add( | |
AutoSizeText( | |
_content, | |
style: TextStyle(fontSize: _fontSize), | |
maxLines: 10, | |
textScaleFactor: 1.5,) | |
); | |
return Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisAlignment: MainAxisAlignment.start, | |
children: contentsOfTiles | |
); | |
} | |
double _determineFontSizeForContent() { | |
int charCount = _content.length + widget.note.title.length ; | |
double fontSize = 20 ; | |
if (charCount > 110 ) { fontSize = 12; } | |
else if (charCount > 80) { fontSize = 14; } | |
else if (charCount > 50) { fontSize = 16; } | |
else if (charCount > 20) { fontSize = 18; } | |
return fontSize; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment