Flutter Listivew hashtags show more issue - flutter

Is it possible to do with flutter?
lot of hashtags came from database. If hashtags length more than 3, that time +10more button there, while we click the button. It will expanded to show all the hashtags. Kindly check my two image, you will get an idea.
First Image
first image
Second Image
second image

Yes, it's possible!
Here is a simple example:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<String> _hashtags = ["Flutter", "Dart", "Google"];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
color: Colors.grey,
height: 50,
child: ListView.builder(
itemCount: _hashtags.length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(3.0),
child: Text("#${_hashtags[index]}"),
);
},
),
),
],
),
),
);
}
}
Interactive example
Output example:

You can acheive that by doing this
RichText(
text: TextSpan(
children: controller.hashtagList.value
.map((e) => WidgetSpan(
style: GoogleFonts.quicksand(
color: Colors.blue, fontSize: 16),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).primaryColor),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'#${e.hashtag}',
),
),
),
)))
.toList()))

Related

flutter bottomsheet with overlay button on top

Can someone give guidance on how to create a bottomsheet with a button on top like below?
I think typically we should be able to achieve it using a stack widget. But not sure how to do this with a bottomsheet. Thanks for your help.
Here is code:
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Test Bottom Sheet app',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo '),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(child: Text("Body"),),
bottomSheet:getBottomSheet() , //Main Center
); //Scaffold
}
Widget getBottomSheet(){
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Stack(
children: [
Padding(
padding: const EdgeInsets.only(top: 30, left: 8.0, right: 8.0),
child: Card(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
shrinkWrap: true,
children: [
Padding(
padding: const EdgeInsets.only(top:20.0),
child: SizedBox(height: 50, child: Text("Postpone Start")),
),
SizedBox(height: 50, child: Text("Postpone Start")),
SizedBox(height: 50, child: Text("Postpone Start")),
],),
),
),
),
Row(
children: [
Card(
color: Colors.orange,
child: FlatButton(onPressed: (){}, child: Text("Header"))),
],
),
],
),
],
);
}
}

Flutter: How to create a beautiful Curve oval shape Container / Divider between other widgets in Flutter

How to create this beautiful curve shape divider in a flutter App.
Simply use this customDivider as your divider
customDivider(String title) {
return Row(
children: [
Expanded(
child: Container(
color: Colors.white,
height: 10,
),
),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(13),
color: Colors.white,
),
child: Center(child: Text(title)),
),
Expanded(
child: Container(
color: Colors.white,
height: 10,
),
),
],
);
}
Here is an example
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
title: Text(widget.title),
),
body: ListView.builder(
itemCount: 5,
shrinkWrap: true,
itemBuilder: (context, index) => listItem(index),
),
);
}
customDivider(String title) {
return Row(
children: [
Expanded(
child: Container(
color: Colors.white,
height: 10,
),
),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(13),
color: Colors.white,
),
child: Center(child: Text(title)),
),
Expanded(
child: Container(
color: Colors.white,
height: 10,
),
),
],
);
}
listItem(int index) {
return Column(
children: [
Container(
height: 200,
width: 200,
margin: EdgeInsets.all(10),
color: index.isEven ? Colors.orange : Colors.deepPurpleAccent,
),
customDivider("your title"),
],
);
}
}
OUTPUT:
There can be many ways to do this in flutter. This is one of the simplest approach.
main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: SO(),
),
);
}
}
class SO extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.pink.shade100,
appBar: AppBar(),
body: Center(
child: CapsuleWidget(
label: 'organizing data'.toUpperCase(),
ribbonHeight: 8,
),
),
);
}
}
class CapsuleWidget extends StatelessWidget {
final Color fillColor;
final Color textColor;
final String label;
final double ribbonHeight;
final double ribbonRadius;
const CapsuleWidget({
Key key,
this.fillColor = Colors.white,
this.textColor = Colors.black,
#required this.label,
#required this.ribbonHeight,
this.ribbonRadius = 1000,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
Expanded(
child: Container(
height: ribbonHeight,
color: fillColor,
),
),
Container(
decoration: BoxDecoration(color: fillColor, borderRadius: BorderRadius.circular(ribbonRadius)),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
label,
style: TextStyle(color: textColor, fontWeight: FontWeight.w500),
),
),
),
Expanded(
child: Container(
height: ribbonHeight,
color: fillColor,
),
),
],
);
}
}
it use Stack class
link url : https://api.flutter.dev/flutter/widgets/Stack-class.html
pseudo code
Stack {
Container(), // background
Contanier(), // white Line
Text() , // center Text
}

In flutter,How to add a button at the bottom and top of ListView

How to add a button,this button bottom of screen and top of listview?
like this
You can just do it using 'Stack' widget.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: _buildBody(),
);
}
Widget _buildBody() {
return Stack(
children: <Widget>[
ListView.builder(
itemCount: 50,
itemBuilder: (context, index) {
return Container(
height: 30,
padding: EdgeInsets.symmetric(horizontal: 20),
child: Text('$index'),
);
},
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
margin: EdgeInsets.symmetric(horizontal: 20, vertical: 40),
width: double.infinity,
child: FlatButton(
child: Text('FlatButton', style: TextStyle(fontSize: 24)),
onPressed: () => {},
color: Colors.green,
textColor: Colors.white,
),
),
),
],
);
}
}

How to include Stratless widget into StatefulWidget?

I want to include StatelessWidget into StatefulWidget.
but having a problem with how to call StatelessWidget in my StatefulWidget?
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
get children => null;
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Generated App',
theme: new ThemeData(
primarySwatch: Colors.blue,
primaryColor: const Color(0xFF2196f3),
accentColor: const Color(0xFF2196f3),
canvasColor: const Color(0xFFfafafa),
),
home: new Container(
child: new MyHomePage(),
),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
#override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Web Apps'),
),
body:
new Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Container(
width: 500,
height: 100,
child: new Center(
child: TextField(
decoration : InputDecoration(
border: OutlineInputBorder(),
hintText: 'Enter Your Phone Number'
),
)
),
),
new Container(
child: new FlatButton(
onPressed: (){},
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(0.0),
side: BorderSide(color: Colors.red)
),
child: new Text('Search',
style: TextStyle(
fontSize: 25
),
),
),
)
],
),
),
);
}
}
class mybuildingdata extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Card(
child: new Text('data'),
);
}
}
here the last StatelessWidget I want to call in StatefulWidget below my Home : Card().
Having issue when I set the StatelessWidget (mybuildingdata) in StatefulWidget but I got errors
You can copy paste run full code below
You can use Column to wrap Card and mybuildingdata
and use Expanded flex to control size
code snippet
body: Column(
children: <Widget>[
Expanded(
flex: 5,
child: new Card(
working demo
full code
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
get children => null;
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Generated App',
theme: new ThemeData(
primarySwatch: Colors.blue,
primaryColor: const Color(0xFF2196f3),
accentColor: const Color(0xFF2196f3),
canvasColor: const Color(0xFFfafafa),
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
#override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Web Apps'),
),
body: Column(
children: <Widget>[
Expanded(
flex: 5,
child: new Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Container(
width: 500,
height: 100,
child: new Center(
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Enter Your Phone Number'),
)),
),
new Container(
child: new FlatButton(
onPressed: () {},
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(0.0),
side: BorderSide(color: Colors.red)),
child: new Text(
'Search',
style: TextStyle(fontSize: 25),
),
),
)
],
),
),
),
Expanded(flex: 1, child: mybuildingdata()),
],
),
);
}
}
class mybuildingdata extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Card(
child: new Text('data'),
);
}
}

Flutter: How to attach a FloatingActionButton to the AppBar?

The Scaffold-Widget only allows to place a FloatingActionButton at the bottom right or the bottom center. How can I place it between AppBar and body like here?
[
It is now possible using:
Scaffold(
appBar: AppBar(title: Text('Title'),),
body: ...,
floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
floatingActionButton: FloatingActionButton(...),
),
Siva Kumar gave nice example, but the second have of the FAB was not clickable. So I made some changes in the code and it works great now!
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double appBarHeight = 200.0;
#override
Widget build(BuildContext context) {
return new Stack(
children: <Widget>[
new Scaffold(
appBar: new PreferredSize(
preferredSize: new Size(MediaQuery.of(context).size.width, appBarHeight),
child: new Container(
color: Colors.blue,
child: new Container(
margin:const EdgeInsets.only(top: 30.0),
child: new Column(children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Row(
children: <Widget>[
new IconButton(
icon: new Icon(
Icons.arrow_back,
color: Colors.white,
),
onPressed: () {
Navigator.pop(context, false);
}
),
new Text(
"Controller Name",
style: new TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white
),
),
],
),
],
),
]
)
)
)
),
body: new Center(
child: new Text('Hello!'),
),
),
new Positioned(
child: new FloatingActionButton(
child: new Icon(Icons.add),
onPressed: () {
print('FAB tapped!');
},
backgroundColor: Colors.blueGrey,
),
right: 10.0,
top: appBarHeight - 5.0,
)
],
);
}
}
we can Achieve it by using stack
and code snippet look like this
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'dart:io';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new PreferredSize(
preferredSize: new Size(MediaQuery.of(context).size.width, 200.0),
child:
new Stack(
alignment: const FractionalOffset(0.98, 1.12),
children: <Widget>[new Container(
color: Colors.blue,
child: new Column(
children: <Widget>[
new Container(
margin: const EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 0.0),
child: new Column(children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Row(
children: <Widget>[
new IconButton(
icon: new Icon(
Icons.arrow_back,
color: Colors.white,
),
onPressed: () {
Navigator.pop(context, false);
}),
new Text(
"Controller Name",
style: new TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white),
),
],
),
],
),
]))
],
)
),new FloatingActionButton(onPressed: (){print("floating button Tapped");},child: new Icon(Icons.add),)],)
),
body: new Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child:
new Container(),
),
);
}
[![output][1]][1]}
for me the solution was, set floatingActionButtonLocation to FloatingActionButtonLocation.endTop
Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.endTop)