Zoom video in Flutter - flutter

I'm using InteractiveViewer class for zooming a video, but sometimes it does not work, I can almost not zoom in or out. I found a way in which I place one finger slightly before the second one and keep it stationary while the other finger moves. But even then the result is hit or miss. When trying it, my success rate of actually zooming in was about 2 per 5.
Does anyone know how to make it work well?
Here is my code:
child: InteractiveViewer(
scaleEnabled: true,
maxScale: 4,
minScale: 0.5,
child: VlcPlayer(
controller: controller,
aspectRatio: 16 / 9,
),
),

Related

Flutter Google Maps how to show active areas with border

I am using the google_maps_flutter: ^2.1.3 package in my Flutter project that I am currently developing and I want to show active regions on the map in the application. I tried to show the active regions on the map using polygons, but I couldn't paint the part outside of these regions a different color. Actually, exactly what I want on the map, everywhere will be gray (to be clear that it is not active), but some areas will be white (to be clear that it is active) surrounded by borders. You can understand exactly what I want by looking at the image below. In this way, there will be more than one active region on the map.
Note: As I mentioned before, I can get this image using polygons, but I cannot make the outside of the polygons gray.
Polygon has a holes parameter which accepts a list of List<LatLng>. What you want to do is create one big polygon that covers the world (or viewport) and set that to be the background color. Then put your actual polygon(s) that you want to draw in the holes section to create a cutout:
Polygon maskedArea = new Polygon(
fillColor: Colors.black.withOpacity(0.5),
polygonId: new PolygonId('test'),
holes: [<LatLng>[new LatLng(10, 10), new LatLng(40, 10), new LatLng(40, 40), new LatLng(10, 40)]],
points: <LatLng>[new LatLng(0, 0), new LatLng(50, 0), new LatLng(50, 50), new LatLng(0, 50)]
);
If you're open to using plugins, there is also syncfusion_flutter_maps which seems to use a custom vector drawing solution to achieve a more robust result through the MapPolygonLayer.inverted constructor (I have not used this plugin myself but have used others from the developer and would anticipate no issues here).
Based on Matt's answer, I came up with the exact solution. First, I couldn't draw a polygon that would cover the entire world, and instead I increased the polygon count to 2. I drew 2 polygons covering the whole world, from 0 to east and from 0 to west. I set the strokeWidth values to 0 so that these polygons do not draw lines from the north pole to the south pole. Later, I showed the active areas in holes, but because my strokeWidth value was 0, the border line did not occur. To avoid this event, I created a new polygon with the fillColor value Colors.transparent and the same coordinates, and set the strokeWidth value to 2.
My sample codes are as follows:
polygon.add(
Polygon(
fillColor: Colors.black.withOpacity(0.5),
polygonId: const PolygonId('test'),
holes: [if (pointsFromService.length != 0) pointsFromService],
points: const [
LatLng(-89, 0),
LatLng(89, 0),
LatLng(89, 179.999),
LatLng(-89, 179.999),
],
visible: true,
geodesic: false,
strokeWidth: 0,
),
);
polygon.add(
Polygon(
fillColor: Colors.black.withOpacity(0.5),
polygonId: const PolygonId('test2'),
points: const [
LatLng(-89.9, 0),
LatLng(89.9, 0),
LatLng(89.9, -179.999),
LatLng(-89.9, -179.999),
],
visible: true,
geodesic: false,
strokeWidth: 0,
),
);
if (pointsFromService.length != 0) {
polygon.add(
Polygon(
fillColor: Colors.transparent,
strokeColor: primaryColor,
polygonId: const PolygonId('test3'),
points: pointsFromService,
visible: true,
geodesic: false,
strokeWidth: 2,
),
);
}
}
The result is as follows:
(Note that the gray area covers the whole world)

How to handle Column overflow in Flutter

I created a simple web app with Flutter.
The app layout is divided in two vertically zones: on the left there is a small top-bottom menu, on the right there is the main content inside a DataTable.
I wrapped the DataTable inside a SingleChildScrollView and everything worked fine.
The left side, on the other hand, keeps giving me a vertical overflow.
The tree on the left side is as follows:
Row(
children: [
//Left side menu
Flexible(
Container(
Column()
), //Container
), //Flexible
//Right side
Flexible(...),
],
), //Row
Obviously it is a very simplified version.
I've tried to insert a SingleChildScrollView in almost all places (Column, Container, Flexible), but it doesn't work and it always returns the error.
A RenderFlex overflowed by 174 pixels on the bottom.
Any solutions?
Thank you!
My approach would be to use MediaQuery to get current height and width of the web window. Then spilt the available width in the ratio of 2:7 maybe? You can play around with the ratio.
Now, lets keep the body of Scaffold to be Container with width as MediaQuery.of(context).size.width and height as ... .height. Now Row with childrens be 2 Expanded widgets with flex 2 and flex 7 respectively. Now we have to portion in the screen in the ratio 2:7.
On the left side, as you said, you need a menu, let it be
Expanded(
flex:2,
child: Column())
And on the other side be-
Expanded(
flex:7,
child: Container(
child: SingleChildScrollView() ///then add your stuff for scrolling purposes.
)
)
learn more about MediaQuery here
learn more about Expanded here

How to set rectangular shape to children of a grid?

I need to make the following page in flutter:
I need to make the following page in flutter. I already tried to do it with a SliverGrid.count(), the problem is that it is the grid that is in charge of establishing the width and height of its children. In addition, the width and height established are always the same(square shaped). Somehow I need to be able to modify the width and height and make it rectangular) so that the children are very similar to how they can be seen in the image
I appreciate any help you can give me
GridView.count(
crossAxisCount: 2,
childAspectRatio: 0.8, // change this value for different results
crossAxisSpacing: 5,
mainAxisSpacing: 5,
padding: EdgeInsets.all(10.0),
children: []
)

How can I add animation on flutter for dynamic list of items?

I am building an app for a game where you can track the upgrade level of armor. Each level has some materials necessary to upgrade. Ex:
Level 1 - 10 of Materials A
Level 2 - 5 of Materials B
Level 3 - 10 of Materials C
I have a page where there is a star rating widget that updates the level property of my armor, when the user changes. And by using a provider, my list of materials updates to only show the remaining ones.
So if my armor is on level 1, it shows:
Level 2 - 5 Materials B
Level 3 - 10 Materials C
And when my armor is on level 2 it shows:
Level 3 - 10 Materials C
What I want to do is to add an animation when that material leaves the screen instead of just hiding it.
This is the setup that I have to show a list of rows containing the information
Column(
children: armor.listOfUpgradeMaterials.map((material) {
return Container(
child: Column(children: [
MaterialByLevelRow(material),
Divider(
color: Theme.of(context).accentColor.withOpacity(0.5),
height: 0,
),
]),
);
}).toList())
Now in my MaterialByLevelRow widget I have an AnimatedContainer with
height: shouldDisplayRow ? 40 : 0,
Is that the best option? With that, several rows will be on the screen but with height zero, isn't that a bad practice?
What if I want to add a slide-in animation with changing the height, would that be possible?
Try using AnimatedList() widget.
Refer to this blog post for more help: https://medium.com/flutter-community/updating-data-in-an-animatedlist-in-flutter-9dbfb136e515

How to get responsive Flutter layouts?

What is best practice for creating a responsive layout? I know that you can use media queries to get sizing information to dictate what to do; e.g. different screens for desktop, tablet, phone.
However, is it common practice to use Expanded or Flex properties to ensure widgets grow or fill the appropriate screen sizes? As a new Flutter developer, trying to understand how the balance is struck on typical use cases.
There are multiple ways to make your UI responsive in Flutter, but just to name a few rules of thumb that will mostly get the job done:
MediaQuery
You can set some widget height or width based on a portion of the screen, for example, creating a SizedBox that will fill 50% of the screen both vertically and horizontally:
SizedBox(
height: MediaQuery.of(context).size.height * 0.5,
width: MediaQuery.of(context).size.width * 0.5,
)
There are other properties that might interest you in the MediaQuery such as the padding from the safe area viewport and so on. You can also find a good article about it here.
LayoutBuilder
One of the most interesting widgets when it comes to build layouts. It will provide you with the parent constraints so you can use it to dynamically adapt your UI.
For example, this will make your child (SizedBox) widget take the parent's maxWidth.
LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints){
return SizedBox(
width: constraints.maxWidth
);
}
)
Some interesting article about LayoutBuilder can be found here.
Flex
By using Flex widgets such as Expanded and Flexible. When used in a Row or Column they'll dynamically adapt based on the constraints imposed by them and along with Column and Row alignments/size they are quite powerful enough to make your UI responsive.
For example, you can have a two Containers in one Row where one uses 1/4 of the view and the other takes 3/4 of the space available.
Row(
children: <Widget>[
Expanded(
flex: 1,
child: Container(),
),
Expanded(
flex: 3,
child: Container(),
),
]
)
Another great article about it can be found here.
Platform
Also, you can always lookup for the underlying platform to make some decisions by using the Platform class getters.
import 'dart:io';
if(Platform.isAndroid) {
print('Running on Android');
}
TL;DR: There are a lot of options that can be played together, you should always look for the best approach for each scenario.
In responsive UI we don’t use hard-coded values for dimension and positions. Use Sizer plugin to get the real time size of the window.
Responsive UI in any screen size device also tablet. Check it this plugin ⬇️
https://pub.dev/packages/sizer
.h - for widget height
.w - for widget width
.sp - for font size
Use .h, .w, .sp after value like this ⬇️
Example:
Container(
height: 10.0.h, //10% of screen height
width: 80.0.w, //80% of screen width
child: Text('Sizer', style: TextStyle(fontSize: 12.0.sp)),
);
I have build many responsive UI with this plugin.
I still think it is better to get the screen size using this commands. You have more control and and you can make your design responsive.
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
There is another package called size_configure that helps you to make your Flutter app responsive. Just import the package and then use it to make your app responsive.
use textSizeMultiplier to set Text size
use imageSizeMultiplier to set Image size
use heightMultiplier to set height size
use weightMultiplier to set weight size
For example:
If you want to set the text size to 28
Divide 28 to 7.9 (because it's text, so we use 'Vertical Block Size')
and then multiply it textSize Multiplier
var width = MediaQuery.of(context).size.width; //width of device
// now we can find the number x% which will return value 10 on multiplying
//by the width of device
var x = (1000/(width))/100;
var ten = width * x; //now ten contains value 10.
//now we can use this value ten like:
ten * 1.5 //returns 15
ten * 3.5 //returns 35
ten * 4 //returns 40
Container(
heigth: ten * 3.7, //height = 37
)