Last active
January 11, 2020 15:46
-
-
Save palcodes/2fa751e39d600b93fdb57eed02cf5c74 to your computer and use it in GitHub Desktop.
Code for live updating listView
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:google_fonts/google_fonts.dart'; | |
class Interests extends StatefulWidget { | |
@override | |
_InterestsState createState() => _InterestsState(); | |
} | |
class _InterestsState extends State<Interests> { | |
List<String> interests = new List(); | |
TextEditingController _textController = TextEditingController(); | |
String newInterest; | |
listInterests(newInterest) { | |
setState(() { | |
print('Interest before = $interests'); | |
interests.add(newInterest); | |
print('Interest after = $interests'); | |
}); | |
} | |
Widget interestListViewWid() { | |
if (interests.isEmpty || interests.length == null) { | |
return Container(); | |
} else { | |
return Container( | |
// height: 0, | |
child: ListView.builder( | |
itemCount: interests.length, | |
itemBuilder: (BuildContext context, int index) { | |
return listItem(newInterest); | |
}, | |
), | |
); | |
} | |
} | |
Widget listItem(newInterest) { | |
return Container( | |
alignment: Alignment.center, | |
decoration: BoxDecoration( | |
color: Colors.black, | |
borderRadius: BorderRadius.circular(50), | |
), | |
child: Row( | |
children: <Widget>[ | |
Text( | |
'#', | |
style: GoogleFonts.redHatText( | |
fontSize: 22, | |
color: Colors.pink[500], | |
), | |
), | |
Text(newInterest, | |
style: GoogleFonts.redHatText( | |
fontSize: 22, | |
color: Colors.white, | |
)), | |
], | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
double height = MediaQuery.of(context).size.height; | |
return Scaffold( | |
resizeToAvoidBottomInset: false, | |
backgroundColor: Colors.black, | |
body: Container( | |
height: 700, | |
decoration: BoxDecoration( | |
image: DecorationImage( | |
image: AssetImage('assets/interests.png'), | |
fit: BoxFit.cover, | |
colorFilter: | |
ColorFilter.mode(Colors.black54, BlendMode.luminosity))), | |
child: Column( | |
children: <Widget>[ | |
Container( | |
alignment: Alignment.center, | |
margin: EdgeInsets.only(top: 50, left: 20, right: 20), | |
child: Material( | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(50)), | |
elevation: 20, | |
shadowColor: Colors.grey[400], | |
child: TextField( | |
maxLines: 1, | |
style: GoogleFonts.redHatText( | |
fontSize: 22, fontWeight: FontWeight.w600), | |
keyboardType: TextInputType.text, | |
autocorrect: true, | |
controller: _textController, | |
decoration: InputDecoration( | |
// contentPadding: EdgeInsets.all(2), | |
filled: true, | |
fillColor: Colors.white, | |
border: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(50), | |
borderSide: BorderSide.none, | |
), | |
// focusedBorder: OutlineInputBorder( | |
// borderRadius: BorderRadius.circular(50), | |
// borderSide: BorderSide(color: Colors.grey[300]), | |
// ), | |
prefix: Container( | |
padding: EdgeInsets.only(left: 20), | |
child: Text( | |
'#', | |
style: GoogleFonts.redHatText( | |
fontSize: 22, | |
color: Colors.pink[500], | |
), | |
), | |
), | |
suffixIcon: IconButton( | |
padding: EdgeInsets.only(right: 20), | |
onPressed: () { | |
newInterest = ""; | |
// String newInterests = | |
newInterest = '#' + _textController.text; | |
print('newInterest = $newInterest '); | |
listInterests(newInterest); | |
}, | |
icon: Icon( | |
Icons.arrow_forward, | |
color: Colors.grey[700], | |
size: 25, | |
), | |
), | |
labelStyle: GoogleFonts.redHatText( | |
fontSize: 22, fontWeight: FontWeight.w600), | |
), | |
), | |
)), | |
//if(interests.isEmpty){ Container()}, | |
// else{ listItem(newInterests)} | |
Expanded(child: interestListViewWid()), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment