Carousel slider with data retrieved from firebase realtime database - flutter

What I would like is to retrieve the data from a Firebase Realtime Database query instead of the List I created manually.
Here I am using a flutter package which is CarouselSlider and I am retrieving the data from a list written manually by myself while what I would like is to retrieve the content of my slider from a query.
Thanks for your help.
Here is my complete code:
import 'package:carousel_slider/carousel_slider.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flyzik/size_config.dart';
class SliderWidget extends StatefulWidget {
#override
State<SliderWidget> createState() => _SliderWidgetState();
}
final List<String> imgList = [
'https://firebasestorage.googleapis.com/v0/b/zfly2020-151d6.appspot.com/o/images_slide%2F3b1ab9f0-671a-11eb-bbaf-6ef0e5b93f8c.jpeg?alt=media&token=2b10908d-edb5-4527-9130-a5e076972e88',
'https://firebasestorage.googleapis.com/v0/b/zfly2020-151d6.appspot.com/o/images_slide%2FCopie%20de%20Red%20and%20black%20Black%20Friday%20sale%20Twitter%20post%20-%20Fait%20avec%20PosterMyWall.jpg?alt=media&token=2c39e317-859c-4560-963a-8374fe34fbcc',
'https://firebasestorage.googleapis.com/v0/b/zfly2020-151d6.appspot.com/o/images_slide%2F6169541506df6_61695418e5c29.jpg?alt=media&token=4c250834-d4f9-4946-93d6-c4bba58766c4',
'https://firebasestorage.googleapis.com/v0/b/zfly2020-151d6.appspot.com/o/images_slide%2F20211211_234252.jpg?alt=media&token=1cb1edcc-bf80-4fbd-a419-2c175e85997f',
'https://firebasestorage.googleapis.com/v0/b/zfly2020-151d6.appspot.com/o/images_slide%2Frap%20(1).jpg?alt=media&token=a2f3996f-b2d9-4cfd-81d2-1fe5c0becb6a'
];
class _SliderWidgetState extends State<SliderWidget> {
#override
Widget build(BuildContext context) {
return Container(
child: CarouselSlider(
options: CarouselOptions(
autoPlay: true,
aspectRatio: 2.0,
enlargeCenterPage: true,
enlargeStrategy: CenterPageEnlargeStrategy.height,
),
items: imageSliders,
),
);
}
final List<Widget> imageSliders = imgList
.map((item) => Container(
child: Container(
margin: EdgeInsets.all(5.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
child: Center(
child: Image.network(
item,
fit: BoxFit.cover,
width: 1500.0,
height: getProportionateScreenHeight(300),
),
)),
),
))
.toList();
}
thank
This the result of all modification
First part
Second part
My database

You can fetch content with a method and use FutureBuilder to fetch it for you automatically.
Future<DataSnapshot> fetchList() async {
const path = 'SET YOUR PATH HERE';
return await FirebaseDatabase.instance.ref(path).get();
}
Wrap your Widget with FutureBuilder
#override
Widget build(BuildContext context) {
return FutureBuilder<DataSnapshot>(
future: fetchList(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
if (snapshot.hasData && snapshot.data != null) {
final imgList = List<String>.from(snapshot.data?.value as List);
return Container(
child: CarouselSlider(
options: CarouselOptions(
autoPlay: true,
aspectRatio: 2.0,
enlargeCenterPage: true,
enlargeStrategy: CenterPageEnlargeStrategy.height,
),
items: imageSliders(imgList),
),
);
}
);
return Text('Error');
}
final List<Widget> imageSliders(List<String> imgList) => imgList
.map((item) => Container(
child: Container(
margin: EdgeInsets.all(5.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
child: Center(
child: Image.network(
item,
fit: BoxFit.cover,
width: 1500.0,
height: getProportionateScreenHeight(300),
),
)),
),
))
.toList();
}
Use imgList to map your data into Widget

Related

Flutter PageView dynamic height

I created a PageView with a fixed value but it is an issue. How i am gonna convert this to dynamic height? SizedBox is in a Column's child. I tried Expanded and Flexible widgets but they did not work.
class BranchViewBottomSection extends ConsumerWidget {
const BranchViewBottomSection({
Key? key,
required this.data,
required this.branchId,
required this.companyId,
}) : super(key: key);
final Map<String, dynamic> data;
final String branchId;
final String companyId;
#override
Widget build(BuildContext context, WidgetRef ref) {
return Column(
children: [
SizedBox(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: data['available_sections'].length,
itemBuilder: (BuildContext context, int index) {
if (data['available_sections'][index]["branchTabValue"] ==
ref.read(tabIndexProvider)) {
return BranchSectionBox(
data: data, index: index, isActive: true);
} else {
return BranchSectionBox(
data: data, index: index, isActive: false);
}
},
),
],
),
),
GestureDetector(
onTap: () {
Navigator.of(context).push(
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) =>
MenuView(
branchId: branchId,
companyId: companyId,
branchData: data,
),
transitionsBuilder:
(context, animation, secondaryAnimation, child) {
const begin = Offset(1.0, 0.0);
const end = Offset.zero;
const curve = Curves.ease;
final tween = Tween(begin: begin, end: end);
final curvedAnimation = CurvedAnimation(
parent: animation,
curve: curve,
);
return SlideTransition(
position: tween.animate(curvedAnimation),
child: child,
);
},
),
);
},
child: Container(
height: 50,
width: MediaQuery.of(context).size.width,
color: Colors.pink,
child: const Center(
child: Text(
"Sipariş vermek için dokunun.",
style: TextStyle(color: Colors.white),
),
),
),
),
Expanded(
child: PageView(
onPageChanged: (v) {
ref.watch(tabIndexProvider.notifier).state =
data['available_sections'][v]['branchTabValue'];
},
children: <Widget>[
BranchViewHomePage(),
BranchViewDetailsPage(),
const BranchViewCommentsPage(),
BranchViewContactPage(),
],
),
)
],
);
}
}
This is the parent.
// ignore_for_file: non_constant_identifier_names, file_names
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:neshapp/comps/common/MainCircularProgressIndicator.dart';
import 'package:neshapp/services/FirestoreService.dart';
import 'package:neshapp/utils/constants.dart';
import '../../providers/BranchViewProviders.dart';
import '../../providers/MenuProviders.dart';
import 'BranchSectionBoxes.dart';
class BranchView extends ConsumerWidget {
final String branchId;
final String companyId;
final String tableNo;
const BranchView(
{Key? key,
required this.branchId,
required this.companyId,
required this.tableNo})
: super(key: key);
#override
Widget build(BuildContext context, WidgetRef ref) {
/*
Uygulamanın her yerinde kullanabilmek için eğer bir şubeye
girilirse şubenin ve markanın id'lerini providerlara veriyorum.
*/
ref.watch(branchIdProvider.notifier).setId(branchId);
ref.watch(companyIdProvider.notifier).setId(companyId);
ref.watch(tableNoProvider.notifier).setTable(tableNo);
return SafeArea(
child: Scaffold(
body: FutureBuilder<DocumentSnapshot>(
future: FirestoreService.getBranchData(companyId, branchId),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
final data = snapshot.data?.data() as Map<String, dynamic>;
return CustomScrollView(
scrollBehavior: const ScrollBehavior(),
slivers: <Widget>[
SliverAppBar(
elevation: 0,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("${data['branch_name']} Şubesi"),
FutureBuilder<DocumentSnapshot>(
future: FirestoreService.getCompanyData(companyId),
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.done) {
final CData =
snapshot.data?.data() as Map<String, dynamic>;
return Container(
height: 40,
width: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: constsColor.black.withOpacity(0.5),
),
child: Image.network(CData['company_logo']),
);
} else {
return const MainCircularProgressIndicator();
}
},
),
],
),
pinned: true,
expandedHeight: 200,
backgroundColor: constsColor.neshMoru,
flexibleSpace: FlexibleSpaceBar(
background: AspectRatio(
aspectRatio: 16 / 9,
child: Stack(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(data['branch_image']),
fit: BoxFit.cover,
),
),
),
Positioned(
bottom: 10,
right: 10,
child: Text(
tableNo,
style: TextStyle(
color: constsColor.white,
fontSize: 18,
),
),
),
],
),
),
),
),
SliverToBoxAdapter(
child: BranchViewBottomSection(
data: data,
branchId: branchId,
companyId: companyId,
),
),
],
);
} else {
return const Center(
child: MainCircularProgressIndicator(),
);
}
},
),
),
);
}
}
expand and flexible i believe are both depend on the parten widget.
how about using the state for that ?

Flutter App : Pick multiple images using Image picker and then drag and drop the selected images in Flutter

This code is for picking multiple images from the gallery using Image Picker Package and showing them on the home screen. After that drag one of the image from the selected images and drop it to drop target by removing the dropped image from the list of selected images. But I'm unable to do as it is showing an exception.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
class Gallery extends StatefulWidget {
const Gallery({Key? key}) : super(key: key);
#override
_GalleryState createState() => _GalleryState();
}
class _GalleryState extends State<Gallery> {
final List<XFile>? selectedImagesList = [];
final List<XFile> dropTargetList = [];
#override
Widget build(BuildContext context) {
double size = 230;
return Scaffold(
appBar: AppBar(
title: const Text('Gallery'),
),
body: Column(
children: [
ElevatedButton(
onPressed: () async {
final List<XFile>? selectedImages = await ImagePicker().pickMultiImage();
if (selectedImages!.isNotEmpty) {
setState(() {
selectedImagesList!.addAll(selectedImages);
});
}
},
child: const Text('Select Images'),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: GridView.builder(
itemCount: selectedImagesList!.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 5),
itemBuilder: (BuildContext context, int index) {
return Draggable<XFile>(
child: Image.file(File(selectedImagesList![index].path),
fit: BoxFit.cover, width: 230, height: 230),
feedback: Image.file(
File(selectedImagesList![index].path),
fit: BoxFit.cover,
width: 230,
height: 230),
childWhenDragging: Container(
color: Colors.red, width: size, height: size),
);
}),
),
),
Container(
width: size,
height: size,
color: Colors.green,
child: DragTarget<XFile>(
builder: ((context, candidateData, rejectedData) {
return Row(
children: dropTargetList
.map((target) => Image.file(File(target.path),
fit: BoxFit.cover, width: size, height: size))
.toList());
}),
onWillAccept: (data) => true,
onAccept: (data) {
setState(() {
dropTargetList.add(data);
selectedImagesList
?.removeWhere((photo) => photo.path == data.path);
});
})),
const SizedBox(height: 200)
],
),
);
}
}
This is the exception while dropping the image https://i.stack.imgur.com/ParUz.png
Emulator screen getting stuck on dropping https://i.stack.imgur.com/5lEsN.png
To prevent the exception from occuring, make sure to only accept data if data is not null:
onWillAccept: (data) => data != null,
This will prevent the exception.
Looking further on why data is null, it's because you don't set it when you create your draggable:
return Draggable<XFile>(
child: ...,
...
data: selectedImagesList![index],
);
Now it will work as you expect it to. Dragging multiple images down causes some overflow, but you should be able to work on that with the exception out of your way :)

How to create carousel slider with firestore image and onclick launch url in flutter?

I want to create carousel slider in flutter with cloud firestore. I created cloud firestore collection with the name of "slider" and i have two fields one is "image" and another one is "url".
Now i need to stream firestore collection in my carousel slider and when user click image, want to launch url.
My Carousel Slider Code
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
class Dashboard extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ListView(
children: <Widget>[
SizedBox(height: 15.0),
CarouselSlider(
options: CarouselOptions(
height: 400.0,
enlargeCenterPage: true,
autoPlay: true,
aspectRatio: 16 / 9,
autoPlayCurve: Curves.fastOutSlowIn,
enableInfiniteScroll: true,
autoPlayAnimationDuration: Duration(milliseconds: 800),
viewportFraction: 0.8),
items: [
Container(
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: DecorationImage(
image: AssetImage('$show Firestore image'),
onPressed: () {
launchURL(
"$ launch firestore url");
}
fit: BoxFit.cover,
),
),
),
],
),
],
);
}
}
Can anyone guide me?
Widget build(BuildContext context) {
var idx = 1;
return Container(
margin: EdgeInsets.only(top: 4.0, bottom: 8.0),
height: getProportionateScreenHeight(150),
width: double.infinity,
decoration: BoxDecoration(
color: Color(0xFF4A3298),
borderRadius: BorderRadius.circular(20),
),
child:StreamBuilder(
stream: FirebaseFirestore.instance.collection(BANNER_URL).snapshots(),
builder: (context, AsyncSnapshot snapshot) {
List list = []..length;
switch (snapshot.connectionState) {
case ConnectionState.none:
return Container(
child: Center(
child: new Text(
'No network. \nPlease, check the connection.')),
);
break;
case ConnectionState.waiting:
return Container(
child: Center(child: new CircularProgressIndicator()),
);
break;
default:
if (snapshot.hasError) {
return Container(
child: Center(
child: Text(snapshot.error.toString()),
),
);
} else if (snapshot.hasData) {
for (int i = 0; i < snapshot.data.size; i++) {
debugPrint("Index is " + idx.toString());
list.add(NetworkImage(
snapshot.data.docs[i].data()['image_url']));
idx++;
}
return ClipRect(
child: Banner(
message: "Publicite aqui",
location: BannerLocation.topEnd,
color: Colors.red,
child: Carousel(
boxFit: BoxFit.cover,
images: list,
autoplay: true,
animationCurve: Curves.fastLinearToSlowEaseIn,
animationDuration: Duration(milliseconds: 2000),
dotSize: 2.0,
dotColor: AppTheme.cuyuyuOrange400,
dotBgColor: AppTheme.cuyuyuTransparent,
indicatorBgPadding: 2.0,
)),
);
}
}
}),
);
}
You can make use of a FutureBuilder to fetch the document snapshot, and on completion, you can store the URLs in a list and use the list for the Carousel
Example code which uses FutureBuilder to fetch a list of urls:
Future getCarouselWidget() async {
var firestore = Firestore.instance;
QuerySnapshot qn = await firestore.collection("carousel").getDocuments();
return qn.documents;
}
Widget build(BuildContext context) {
var idx = 1;
return Container(
child: FutureBuilder(
future: getCarouselWidget(),
builder: (context, AsyncSnapshot snapshot) {
List<NetworkImage> list = new List<NetworkImage>();
if (snapshot.connectionState == ConnectionState.waiting) {
return new CircularProgressIndicator();
} else {
if (snapshot.hasError) {
return new Text("fetch error");
} else {
//Create for loop and store the urls in the list
for(int i = 0; i < snapshot.data[0].data.length; i++ ) {
debugPrint("Index is " + idx.toString());
list.add(NetworkImage(snapshot.data[0].data["img_"+idx.toString()]));
idx++;
}
return new Container(
height: 250.0,
child: new Carousel(
boxFit: BoxFit.cover,
images: list, <== Set the list here
autoplay: true,
dotSize: 4.0,
indicatorBgPadding: 4.0,
animationCurve: Curves.fastOutSlowIn,
animationDuration: Duration(milliseconds: 1000),
));
}
}
}),
);

There are two carousel slides running in same line this app but I want only one. please tell me what is Problem

There is no error in this code
but nothing is understood as to what is causing the two slider.
See in this android emulator working two carousel.
please tell me what is a problem in this code.
Do not understand what to write now, how long has this stockoverflow been told, add some more details,
minds spoiled, so I am writing this, Sorry, do not pay attention to this, pay attention to question.
import 'dart:convert';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class Carousel extends StatefulWidget {
#override
_CarouselState createState() => _CarouselState();
}
class _CarouselState extends State<Carousel> {
var api = Uri.parse('http://192.168.43.162/flutter/bannerApi.php');
var response;
var bannerApi;
#override
void initState() {
super.initState();
// for loading
fetchData();
}
fetchData() async {
response = await http.get(api);
print(response.body);
bannerApi = jsonDecode(response.body);
setState(() {});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: response != null
? Stack(
children: List.generate(
bannerApi.length,
(index) => CarouselSlider(
items: [
//1st Image of Slider
Container(
margin: EdgeInsets.all(6.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.0),
image: DecorationImage(
image: NetworkImage(bannerApi[index]['img']),
// image: AssetImage(assignmets[index]['img']),
fit: BoxFit.cover,
),
),
),
],
//Slider Container properties
options: CarouselOptions(
height: 180.0,
enlargeCenterPage: true,
autoPlay: true,
aspectRatio: 16 / 9,
autoPlayCurve: Curves.fastOutSlowIn,
enableInfiniteScroll: true,
autoPlayAnimationDuration: Duration(milliseconds: 800),
viewportFraction: 0.8,
),
),
))
: CircularProgressIndicator(
backgroundColor: Colors.white,
)),
);
}
}
This is a api data.
[{"img":"https:\/\/images.unsplash.com\/photo-1517245386807-bb43f82c33c4?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80"},{"img":"https:\/\/images.unsplash.com\/photo-1517245386807-bb43f82c33c4?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80"},{"img":"https:\/\/images.unsplash.com\/photo-1517245386807-bb43f82c33c4?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80"},{"img":"https:\/\/images.unsplash.com\/photo-1517245386807-bb43f82c33c4?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80"},{"img":"https:\/\/images.unsplash.com\/photo-1517245386807-bb43f82c33c4?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80"},{"img":"https:\/\/images.unsplash.com\/photo-1517245386807-bb43f82c33c4?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80"}]
Instead of your stack I am using a container.
Container(
child: CarouselSlider(
items: List.generate(
bannerApi.length,
(index) => Container(
margin: edgeInsects.all(6.0)
...

Flutter. GridView inside Container

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'Login.dart';
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
image:DecorationImage(
image: AssetImage("images/black_background_logo.png"),
fit: BoxFit.cover,
)
),
child: Column(
children: [
CarouselDemo(),
HomePanel()
],
),
);
}
}
List<String> images = [
'https://skalka-app.ru/banners/1.png',
'https://skalka-app.ru/banners/2.png',
'https://skalka-app.ru/banners/3.png',
] ;
class CarouselDemo extends StatelessWidget {
CarouselController buttonCarouselController = CarouselController();
#override
Widget build(BuildContext context) => CarouselSlider(
options: CarouselOptions(
height: MediaQuery.of(context).size.height*0.7,
viewportFraction: 1.0,
enableInfiniteScroll: true,
reverse: false,
autoPlay: true,
autoPlayInterval: Duration(seconds: 8),
autoPlayAnimationDuration: Duration(milliseconds: 800),
autoPlayCurve: Curves.fastOutSlowIn,
),
items: images.map((i) {
return Builder(
builder: (BuildContext context) {
return Container(
//width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height*0.7,
decoration: BoxDecoration(
color: Colors.amber
),
child: Image.network(i,fit: BoxFit.cover, height: MediaQuery.of(context).size.height*0.7,)
);
},
);
}).toList(),
);
}
class HomePanel extends StatelessWidget {
#override
Widget build(BuildContext context) {
final double height = MediaQuery.of(context).size.height;
List<String> data = <String>["Twitter", "Reddit", "YouTube", "Facebook",
"Vimeo", "GitHub", "GitLab", "BitBucket", "LinkedIn", "Medium",
"Tumblr", "Instagram", "Pinterest"];
List<RaisedButton> myWidgets = data.map((item) {
return new RaisedButton(
child: new Text(item),
onPressed: () async {
}
);
}).toList();
GridView myGrid = GridView.count(
crossAxisCount: 3,
children: myWidgets
);
return Container(
height: height*0.3,
width: MediaQuery.of(context).size.width,
color: Colors.red,
child: myGrid
);
}
}
I'm trying to add a GridView to a Container, but an indent appears at the top. Please tell me how to fix this?
I painted the Container red to show that there is a padding on top. I could not find a solution to this problem on the Internet. I'm new to Flutter, maybe I missed an important point in building this widget.
You can try wrap GridView with a MediaQuery.removePadding() then set removeTop property to True.
MediaQuery.removePadding(
context: context,
removeTop: true,
child: GridView(
.......
)
);
I have used your code pretty much, just for the Carousel, I have used the ListView.builder(). Rest is fine.
The catch is to use Expanded class inside your Column() to take the height automatically for the Carousel
Follow the code along, and see the result as well, no extra space in the UI in the GridView
class _MyHomePageState extends State<MyHomePage> {
List<String> images = [
'https://skalka-app.ru/banners/1.png',
'https://skalka-app.ru/banners/2.png',
'https://skalka-app.ru/banners/3.png',
];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
height: double.infinity,
child: Column(
children: [
// Expanded used to take up the space
Expanded(
// ListView.builder, use your carousel here
child: ListView.builder(
shrinkWrap: true,
itemCount: images.length,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index){
// look at this as well, no height, only width
// given for the image
return Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(images[index])
)
)
);
}
)
),
HomePanel()
],
),
)
);
}
}
class HomePanel extends StatelessWidget {
#override
Widget build(BuildContext context) {
final double height = MediaQuery.of(context).size.height;
List<String> data = <String>["Twitter", "Reddit", "YouTube", "Facebook",
"Vimeo", "GitHub", "GitLab", "BitBucket", "LinkedIn", "Medium",
"Tumblr", "Instagram", "Pinterest"];
List<RaisedButton> myWidgets = data.map((item) {
return new RaisedButton(
child: new Text(item),
onPressed: () async {
}
);
}).toList();
GridView myGrid = GridView.count(
crossAxisCount: 3,
children: myWidgets
);
return Container(
height: height*0.3,
width: MediaQuery.of(context).size.width,
color: Colors.red,
child: myGrid
);
}
}
Result
Look at the design closely in the result, no extra spacing or padding