How to Navigate to other Screen using Carousel - flutter

I wanted to have a carousel with 5 photos and when I press any of the images I want to navigate to a different screen. I watched many videos but couldn't find any solutions. I used carousel_slider package.
CarouselSlider(
CarouselOptions(height: 400.0),
items: [1,2,3,4,5].map((i) {
return Builder(
builder: (BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(
color: Colors.amber
),
child: Text('text $i', style: TextStyle(fontSize: 16.0),)
);
},
);
}).toList(),
)
Imagine I have 5 different pages and when I press any of the pictures in the carousel then I should be navigated to a particular page. If I use a Gesture detector how can I navigate him using navigator.push?

Try using ManuallyControlledSlider from
https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/lib/main.dart but change onPressed callback inside
Iterable -> RaisedButton to navigate on specific page.

Related

Is it possible to Repeat Icons in flutter like ImageRepeat

I am wondering if it is possible to repeat an actual icon widget like the image I have attached.
Currently getting this result using ImageRepeat but would like to be able to use and actual icon so it can be modular and the icon can change.
( the repeating image can currently change but I don't want to have to create 100 images of icons. )
Current Solution:
SizedBox.expand(
child: Image.asset(
_backGroundImage,
repeat: ImageRepeat.repeat,
)),
try Wrap:
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
color: Colors.orange,
child: Wrap(
children: List<Widget>.generate(2000, (int index) {
return Icon(Icons.add);
}),
),
),

Searching for the name of a specific menu - Flutter

So I'm searching for a Menu often found in a Settings Screen. It's used to select a Setting.
It opens when you press on a ListTile and then it fills the mayority of the Screen, while the borders are transparent. In the menu you have to select one of the options.
An example usecase of that would be to select a Language(onTap of the ListTile opens a Menu where you can select between all the avaliable languages)
It is similar to that of a PopupMenuButton, however as already mentioned it fills most of the screen, and the individual selectable items have a radiobutton in front of the text(probably RadioListTiles)
I hope someone gets what I'm talking about, because for the past 3 hours I'm searching for this widget but just find articles about the PopupMenuButton over and over.
Edit: I finally found an app that uses the feature I'm looking for
: https://imgur.com/a/A9k71io
By clicking on the first ListTile in the first Picture, the dialog in the second picture opens up.
Hopefully this custom widget is something roughly what you want, try to copy and paste it in your project and play with it.
this is made using the Dialog widget, to exit the Dialog you can tap out of it/ press the device back arrow and I added a small back icon on the top left corner.
tell me if it helped :)
class TestPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
final deviceSize = MediaQuery.of(context).size;// the device size
return Scaffold(
body: Center(
child: ListTile(
tileColor: Colors.grey[300],
title: Text(
'Language',
style: TextStyle(fontSize: 25),
),
onTap: () => showDialog(
context: context,
builder: (context) => Dialog(
insetPadding: EdgeInsets.all(20),
child: Container(
color: Colors.white,
height: deviceSize.height,
width: deviceSize.width,
child: Column(
children: [
Row(
children: [
IconButton(
color: Colors.red,
icon: Icon(Icons.arrow_back),
onPressed: () => Navigator.of(context).pop(),
),
],
),
Spacer(),
Text('Pick A Language'),
Spacer(),
],
),
),
),
),
),
),
);
}
}

Flutter Carousel no Image and some other difficulties

I am new to flutter as well as app dev.
I was trying to implement a STAEFUL carousel that responds and redirects to a certain link when an image in the carousel is clicked.
Here are the problems I faced.
I am not getting how to make the carousel images stateful should I implement a Gesture detector or Inkwell?
Should Every image has to be tagged within the [LIST] or the entire carousel can be tagged with a single inkwell or gesture detector?
Please have a look in the code, is it possible to map the redirect addresses as a list! (This will be much easier to add images, but what is bothering me here is, do I have to recompile and upload the app to AppStore each time I add new image address and respective redirect link?)
Most importantly the carousel isn't showing the images only the URL
what do these mean in this part of the code?
[LIST].map((i) {}
and
'text $i'
items: [imgList].map((i) {
return Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(color: Colors.blueAccent),
child: Text('text $i', style: TextStyle(fontSize: 16.0),)
);
here is the entire code
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
//import 'package:carousel_slider/carousel_controller.dart';
import 'package:carousel_slider/carousel_options.dart';
List<String> imgList =
[
'https://static.scientificamerican.com/sciam/cache/file/92E141F8-36E4-4331-BB2EE42AC8674DD3_source.jpg',
'https://icatcare.org/app/uploads/2018/07/Thinking-of-getting-a-cat.png',
];
List<String> redirectList =
[
'img 1 redirect link',
'img 2 redirect link',
]; //yet to be configured
class VerticalSliderDemo extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
child: CarouselSlider(
options: CarouselOptions(
aspectRatio: 2.0,
enlargeCenterPage: true,
scrollDirection: Axis.horizontal,
autoPlay: true,
autoPlayInterval: Duration(seconds: 3),
autoPlayAnimationDuration: Duration(milliseconds: 800),
autoPlayCurve: Curves.fastOutSlowIn,
),
items: [imgList].map((i) {
return Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(color: Colors.blueAccent),
child: Text('text $i', style: TextStyle(fontSize: 16.0),)
);
}
).toList(),
),
);
}
}
https://github.com/Amit506/courouselexample
in this link i have uploaded correct working courousel slider .
if you want to know the differenve between text widget and image widget you should refer to official documentation of flutter they have written all the information of widgets.
https://api.flutter.dev/flutter/widgets/Image-class.html
https://github.com/Amit506/dart-foods/blob/main/lib/TabBars.dart/TabBar1.dart
in this link i have used courousel builder in one of my project you can refer to it for advance courousel slider.
To make image responsive to tap you only have to wrap image widget with gesturedetector /inkwell or any other widgets available In this case you can wrap image.Network
You can't show picture in text widget.for showing image from url you have to use Image.Network () instead of text widget. text widget is used to show only text .
to show any network image you can do
Image.Network('url'). If u want i can can show you code

Carousel animation flutter with photos

I want to do a carousel animation with photos that starts by itself and doesn't need to be touch to move the photos (slide)and the photos to go to the right . The app that i am working in it's flutter .
You can use carousel_slider flutter package to achieve this. You can refer to the GitHub for documentation.
In Short,
Add carousel_slider: ^2.2.1 to your pubspec.yaml
import 'package:carousel_slider/carousel_slider.dart';
Simply create a CarouselSlider widget, and pass the required params:
pass autoPlay option as true on CarouselOptions()
CarouselSlider(
options: CarouselOptions(
height: 400.0,
enableInfiniteScroll: true,
autoPlay: true
),
items: [1,2,3,4,5].map((i) {
return Builder(
builder: (BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(
color: Colors.amber
),
child: Text('text $i', style: TextStyle(fontSize: 16.0),)
);
},
);
}).toList(),
)

Flutter - Change background color of a widget

Widget _buildImageColumn() => Container(
decoration: BoxDecoration(
color: Colors.black26,
),
child: Column(
children: [
_buildImageRow(1),
_buildImageRow(3),
],
),
);
Widget _buildDecoratedImage(int imageIndex) => Expanded(
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 10, color: Colors.black38),
borderRadius: const BorderRadius.all(const Radius.circular(8)),
),
margin: const EdgeInsets.all(4),
child: Image.asset('images/pic$imageIndex.jpg'),
),
);
Widget _buildImageRow(int imageIndex) => Row(
children: [
_buildDecoratedImage(imageIndex),
_buildDecoratedImage(imageIndex + 1),
],
);
The above code is taken from flutter website.
I want to change the background color of the widget with some animation (image). But after first tab, i don't want to execute the tap function again.
I tried to move _buildDecoratedImage to a statefulwidget and i can animate the particular widget and disable tap on that widget only. I am not able to disable tap on other three images (widgets).
though i can animate the background without moving _buildDecoratedImage to a statefulwidget and disable the tap of all the widget. But the entire screen is rebuilt.
Is there any way to achieve this without using streams?
One of the image must be tapped and animate the background and every image should not be tapped after that.
Please suggest the best solution for this.
If you don't want to use bloc plugin, you may want to consider using Stream to listen for changes in values set.
final _imageIndex = StreamController<int>.broadcast();
Stream<int> get imageIndex => _imageIndex.stream;
// Update image index
updateImageIndex(int index) {
_imageIndex.sink.add(index);
}
Then to update, you can call updateImageIndex(index). To listen for changes, you can set imageIndex on a StreamBuilder - this gets rebuilt when changes on Stream is detected.
StreamBuilder<int>(
stream: imageIndex,
builder: (context, AsyncSnapshot<int> snapshot) {
if (snapshot.hasData) {
debugPrint('Image index: ${snapshot.data}');
}
}
)