Flutter Webview scrolling is leggy or not so smooth - flutter

Note I have not added complete code.
In below code I am rendering CircularProgressIndicator and InAppWebView at once to avoid the white screen displayed (Apart from splash and launch screen) by the InAppWebView at the time of loading.
I am using opacity to display one widget at a time. In my example initially
CircularProgressIndicator is visible only for 5 seconds. Than after those 5 seconds InAppWebView is displayed which was kept invisible.
Using of Stack layout makes webview scroll leggy. I need to figure out on how to render CircularProgressIndicatora and InAppWebView together without having to use stack.
body: WillPopScope(
onWillPop: onWillPop,
child: Stack(
children: <Widget>[
Opacity(
opacity: _isLoadingPage ? 1.0 : 0.0,
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.deepPurple),
),
),
),
Opacity(
opacity: _isLoadingPage ? 0.0 : 1.0,
child: InAppWebView(
initialUrl: 'https://www.theonlineindia.co.in',
),
),
],
),
),

Related

Flutter PageView turn and flip animation for book app UI using After Effects

I want to perform animation in my flutter app specifically in Pageview widget to swipe pages such as a real book as in the image
Try this, flip_widget:
FlipWidget(
key: _flipKey,
child: Container(
color: Colors.blue,
child: Center(
child: Text("hello"),
),
),
)

loading icon before SVG image Loading

i am created an SVG image for background, but it is loaded after some time, the issue is:
when it is not loaded yet all widgets appears randomly. i just need a loader after the image loaded it page widget appears.
the code is:
Scaffold(
appBar: const _CustomNotificationAppBar(),
body: isFinished
? SingleChildScrollView(
child: Stack(
children: [
//notification background
Opacity(
opacity: 0.42,
child: SvgPicture.asset(
'assets/images/notification_background.svg',
),
),
IconButton(
icon: const Icon(
Icons.notifications_active_outlined,
),
onPressed: () {})),
],
),
)
: const Center(
child: CircularProgressIndicator(),
),
);
well if I understands you well and as long as your SVG is loading from the device "asset",
there should not be delay in first place.
I think the problem is you emulator or physical device is too slow , And you may face this problem in debug only
try to run flutter build APK and install that generated APK in your phone and check if problem remains.
however you can achieve that also like this
SvgPicture.asset(
'assets/images/notification_background.svg',
placeholderBuilder: (context) => Text("I am Loading"),
),
You can wrap it in a Container, and it will work.
For eg:
Container(
//height :desired height,
//width : desired width
child: Opacity(
opacity: 0.42,
child: SvgPicture.asset(
'assets/images/notification_background.svg',
),
))
You can pass a placeholderBuilder to your SvgPicture.asset like this:
SvgPicture.asset(
'assets/images/notification_background.svg',
placeholderBuilder: (context) => Icon(Icons.your_desired_icon),
),
You can also wrap the Icon with a SizedBox if you need to comply with a certain size, or replace it by any other widget that you wish.
More info about the widget you're using is available in its API docs.

can't scroll after adding a transparent container

I have a PageView with Stack children. those Stack widgets contain transparent containers that controlls the opacity level relative to the scroll position.
the expense is that now I am unable to scroll what's in the background. what is the best way to add that layer and keep my backround scroll active.
Updating the Listview widget seems expensive as the opacity transion changes that is why I tried to keep it separate
I have something like this
Stack(children: [
Scaffold(
body: SafeArea(
child: Container(
color: Colors.white,
child: ListView..., // the listView I am trying to scroll
),
),
),
currIndex == 1 ? MainCardTransitionContainer() : Container(), // the layer with opacity
]),
Try IgnorePointer:
Stack(children: [
Scaffold(
body: SafeArea(
child: Container(
color: Colors.white,
child: ListView..., // the listView I am trying to scroll
),
),
),
currIndex == 1 ? IgnorePointer(ignoring: true, child:MainCardTransitionContainer(),) : Container(), // the layer with opacity
]),
Try this
Stack(children: [
currIndex == 1 ? MainCardTransitionContainer() : Container(), // the layer with opacity
Scaffold(
body: SafeArea(
child: Container(
color: Colors.white,
child: ListView..., // the listView I am trying to scroll
),
),
),
]),
It's because the top widget of stack is kept at background and last widget is placed in foreground.
In short keep background element at top of stack

How to rotate a larger-than-screen image without the overflow being clipped off in Flutter?

I have this image that I would like to display full screen and rotate in the background:
Here it is filling the screen correctly:
The problem is, when it rotates, the sides have been clipped off:
I've tried every type of box fit. I've tried sizing the container width to double.infinity. I've tried wrapping the image in a SingleChildScrollView. I've tried putting overflow: Overflow.visible on the stack. All day trying things, but nothing seems to be working.
The image needs to continuously fill the screen while rotating. How can I code it so that the edges aren't clipped off?
Here's my code:
class FirstScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Stack(
children: <Widget>[
SpinPerfect(
infinite: true,
duration: Duration(seconds: 10),
child: Image.asset(
'assets/images/star-burst.png',
fit: BoxFit.none,
),
),
Container(
child: Center(
child: Text('This is Screen 1'),
),
),
],
),
),
);
}
}
Note: I am currently rotating it using SpinPerfect from the animate_do package, but the same clipping problem happens when using Transform.rotate.
Thanks in advance for any direction!
Here is a solution that works very well:
Use SpinPerfect from the animate_do package (https://pub.dev/packages/animate_do) in combination with the photo_view package (https://pub.dev/packages/photo_view).
SpinPerfect(
infinite: true,
spins: 1,
duration: Duration(seconds: 60),
child: PhotoView(
disableGestures: true,
backgroundDecoration: BoxDecoration(color: Colors.transparent),
initialScale: PhotoViewComputedScale.covered * 2.7,
imageProvider: AssetImage('assets/images/background.jpg'),
),
)
Thanks to the creator of the animate_do package for the idea. (Very cool dude!)

Make background of CircularProgressIndicator transparent in flutter

I have integrated CircularProgressIndicator in my app on login. The indicator is visible as desired but it hides my login screen with a white overlay. I want to make its background transparent instead of white. I tried to give the background color of CircularProgressIndicator but it doesn't make any change. Here is my code:
child: !_isLoading ? _loginScreen(loginBloc.state) : Center(
child: const SizedBox(
width: 40,
height: 40,
child: CircularProgressIndicator(),
),
)
Thank you.
You can use Stack with different opacity on its childern.
E.g.
Stack(
children: <Widget>[
Opacity(
opacity: 1, // You can reduce this when loading to give different effect
child: AbsorbPointer(
absorbing: _isLoading,
child: _loginScreen(loginBloc.state),
),
),
Opacity(
opacity: _isLoading ? 1.0 : 0,
child: CircularProgressIndicator(),
),
],
);
In case you want working solution, I use it heavily in https://github.com/yagnyam-in/proxy-flutter/blob/master/lib/widgets/loading.dart, https://github.com/yagnyam-in/proxy-flutter/blob/master/lib/widgets/async_helper.dart