How to make flutter animation play full-screen when modal bottom sheet has been raised? - flutter-layout

I am trying to add a confetti animation to modal bottom sheet using confetti package when it is raised. But it is not working as intended - animation is being cut in the middle of the screen. It works as intended when I call the animation from button press. Desired result is like on button press, but should be when modal bottom sheet is raised.
I have tried wrapping ConfettiWidget inside Expanded, Positioned.fill, also Flexible, but these don't work.
EDIT:
Did some testing and it seems that the problem is present only on iOS devices. Also, it probably is worth mentioning that the animation is way slower on Android device (both physical and virtual) than it is on an iPhone.
See gifs below:
On Build:
On button press:
(How it should look on the build)
Code:
#override
void initState() {
confController = ConfettiController(duration: Duration(seconds: 5));
WidgetsBinding.instance!.addPostFrameCallback((_) {
confController.play();
});
super.initState();
}
#override
void dispose() {
confController.dispose();
super.dispose();
}
Widget build(BuildContext context) {
return Container(
color: Colors.black,
child: Stack(
children: [
Align(
alignment: Alignment.topCenter,
child: ConfettiWidget(
confettiController: confController,
blastDirectionality: BlastDirectionality.explosive,
particleDrag: 0.05,
emissionFrequency: 0.1,
gravity: 0.3,
colors: [
Colors.red,
], // manually specify the colors to be used
),
),
Container(
width: 500,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RawMaterialButton(
onPressed: () {
confController.play();
},
fillColor: Colors.white,
)
],
),
)
],
),
);
}

Needed to set the ConfettiWidget parameter canvas to MediaQuery.of(context).size * 2. Works as intended now (tested on both smaller and bigger devices (biggest was iPad 12.9-inch)). Code looks like this now:
ConfettiWidget(
confettiController: confController,
blastDirectionality: BlastDirectionality.explosive,
particleDrag: 0.05,
emissionFrequency: 0.1,
gravity: 0.3,
canvas: MediaQuery.of(context).size * 2,
colors: [
Colors.red,
],
)

Related

Flutter screenshot without using RepaintBoundary

I am working on a drawing app. I can get a screenshot of a widget using RepaintBoundary but I need to update it with a button which is outside. In my case, I can clear the list of points with a FlatButton but my Container is not clearing because of RepaintBoundary I need to get a screenshot of my Container without RepaintBoundary or I should update my Container from outside they both works for me. Thanks.
return
SingleChildScrollView(//physics: NeverScrollableScrollPhysics(),
child: Column(
children: <Widget>[
RepaintBoundary(
key: _signKey,
child: new Container(
width: 100.0 * MediaQuery.of(context).devicePixelRatio ,
height: 150.0 * MediaQuery.of(context).devicePixelRatio,
color: Colors.black12,
child: GestureDetector(
onPanUpdate: (DragUpdateDetails details) {
setState(() {
RenderBox object = context.findRenderObject();
Offset _localPosition =
object.globalToLocal(details.globalPosition);
points = new List.from(points)
..add(_localPosition);
});
},
onPanEnd: (DragEndDetails details) => points.add(null),
child: new CustomPaint(
painter: new DrawingPainter(points: points),
size: Size.infinite,
),
),
),
),
Row(
children: <Widget>[
FlatButton( //Button to clear container
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8)),
color: Colors.redAccent,
textColor: Colors.black,
onPressed: (){
setState(() {
points.clear();
});
},
child: Text('Sil'),
),
],
),
],
),
);

I have created two 'raised buttons' but only one is showing. What is the problem here?

I have made total 14 screens in the application, you may see in the code whose link i have provided below. Two raised buttons i have created, one button named 'Wonders of world' on pressing will take it to second screen the other button named 'wonders of India' will take it to eleventh screen. Unfortunately The first button wonder of world is not visible. Why it is not showing?
This is the image on running the app, you can see only one raised button visible.
The link of the code
Just wrap your both button in Row Like
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RaisedButton(
child: Text("Wonders of World"),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => SplashUI()));
},
color: Colors.red,
textColor: Colors.yellow,
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
splashColor: Colors.grey,
),
RaisedButton(
child: Text("Wonders of India"),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => EleventhScreen()));
},
color: Colors.red,
textColor: Colors.yellow,
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
splashColor: Colors.grey,
)
],
),

Building my own drawer with ListView occurs tileWidth != leadingSize.width

I use ListView instead of Drawer and I want to make it collapsible, just like Dashboard style Drawer.
My solution is click a button, and setState the width of the SizedBox.
Somehow it spits out tileWidth != leadingSize.width
is there any solution to this error?
Widget _menu(bool isOpen) {
return SizedBox(
width: isOpen ? 250 : 0,
child: ListView(
children: [
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("MENU"),
ListTile(title:Text('item1')),
ListTile(title:Text('item2')),
],
),
],
),
);
}
Change ListTile to simple Text widget won't cause any issue.
I am making a project on flutter web.
You can try by this Container inside ListTile
ListTile(
leading: Container(
width: 64,
// ..
),
// ..
);

Flutter: How can I put "header image" and "ListView" in same scroll?

I want to make header image and ListView in same scroll. But the code like below doesn't work:
SingleChildScrollView(
child: Column(
children: <Widget>[
HeaderImage(),
ListView(...)
]
)
)
I know ListView can't be below Column() directly. I know the way to use Expand() or Container with height or SizedBox, but these way can't make header image and ListView in same scroll. How to do these in same scroll? (HeaderImage widget is example.)(I must use ListView.)
I used to see this style in the world of web frequently.
You can use:
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
flexibleSpace: FlexibleSpaceBar(
background: Container(
color: Colors.transparent,
child: Image(
image: NetworkImage('your image url here'),
fit: BoxFit.cover,
),
)
),
expandedHeight: 300,
backgroundColor: Colors.transparent,
actionsIconTheme: IconThemeData.fallback(),
),
SliverList(
delegate: SliverChildListDelegate(
[
Column(
children: <Widget>[
for(var index = 0;index<your_data.length;index++) // Dont put comma
your List Design here
]
)
]
)
)
]
)

Gradient Text in Flutter

I was wondering if it is possible to create a gradient over text
Flutter. There is a gist of text gradient using Dart's ui, but it is kinda long and I was hoping to be simpler.
You can use ShaderMask for that task. In ShaderMask, you need to set the BlendMode to BlendMode.srcIn, "src" means the widget to apply the gradient to (in this case Text), "in" means only show the part of the Text where it overlaps with the background which is the text itself (so the gradient doesn't get applied on the background):
import 'package:flutter/material.dart';
class GradientText extends StatelessWidget {
const GradientText(
this.text, {
required this.gradient,
this.style,
});
final String text;
final TextStyle? style;
final Gradient gradient;
#override
Widget build(BuildContext context) {
return ShaderMask(
blendMode: BlendMode.srcIn,
shaderCallback: (bounds) => gradient.createShader(
Rect.fromLTWH(0, 0, bounds.width, bounds.height),
),
child: Text(text, style: style),
);
}
}
Usage
GradientText(
'Hello Flutter',
style: const TextStyle(fontSize: 40),
gradient: LinearGradient(colors: [
Colors.blue.shade400,
Colors.blue.shade900,
]),
),
Live Demo
Taken from here, you can use Text's style painter.
Create the shader,
final Shader linearGradient = LinearGradient(
colors: <Color>[Color(0xffDA44bb), Color(0xff8921aa)],
).createShader(Rect.fromLTWH(0.0, 0.0, 200.0, 70.0));
then use it in the TextStyle's foreground
Text(
'Hello Gradients!',
style: new TextStyle(
fontSize: 60.0,
fontWeight: FontWeight.bold,
foreground: Paint()..shader = linearGradient),
)
Source code
Use simple_gradient_text package and create GradienText
GradientText(
'Gradient Text Example',
style: TextStyle(
fontSize: 40.0,
),
colors: [
Colors.blue,
Colors.red,
Colors.teal,
],
),
First, we import Pkg
Link For PKG
Radial gradient
GradientText(
'Gradient Text Example',
style: TextStyle(
fontSize: 40.0,
),
gradientType: GradientType.radial,
gradientDirection: GradientDirection.ttb,
radius: 6,
colors: [
Color(0xff159DFF),
Color(0xff002981),
],
),
Linear gradient
GradientText(
'Gradient Text Example',
style: TextStyle(
fontSize: 40.0,
),
gradientType: GradientType.linear,
gradientDirection: GradientDirection.ttb,
radius: .4,
colors: [
Color(0xff159DFF),
Color(0xff002981),
],
),

Resources