start animation when opening home screen - flutter-animation

I'm new to flutter framework.
I faced such a problem that I'm tedious to start the animation when the application is running, I just can't figure out how to do it
body: Container(
child: Column(
children: <Widget> [
AnimatedOpacity(
opacity: opacityLevel,
duration: Duration(seconds: 3),
child: Image.network('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR85x1PkEHJwgEOOX0Zvjrz6AdfkG0IpO8lGg&usqp=CAU'),
),
I tried to find a solution on other sources, but I didn’t find anything, maybe it can’t be done at all

Related

Flutter IOS mobile app - clicking on UI elements covering WebView triggers videos in webview's iframes

I have an issue with a Flutter IOS app
I have a webview with a youtube video embedded in an iframe
I have a widget containing the webview positioned under a flutter regular widget (such as a bottom or top bar, or a dialog)
Issue is that tapping on the flutter element above the webview actually starts the youtube video, even though the tap was NOT done directly on the webview.
This only happens on IOS. Android works fine.
Does anyone know how to prevent this from happening? I would like to have a dialog shown over the webview, but not start the video when a dialog option is tapped.
I suspect iframe is the issue here
Here is the code for webview part (I use InAppWebView here, but behavior is the same with WebView flutter), and photos for both android and ios apps
body: ListView(
children: [
const SizedBox(
height: 700,
),
SizedBox(
height: 400,
child: InAppWebView(
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(),
),
onWebViewCreated: (InAppWebViewController controller) {
controller.loadData(
data:
'<iframe id="inlineFrameExample" title="Inline Frame Example" width="500" height="200" src="https://www.youtube-nocookie.com/embed/-dLDifsmJo4?wmode=opaque"></iframe>',
);
},
),
),
],
),

Swipe back in iOS webview flutter

in my Flutter app, I use web view. For android, I use willpopscope so when someone presses the back button review page will pop to its previous state.
But in iOS willpopscope is not working, I have tried cupertino_back_gesture package it also not working.
I also tried the gesture detector it works but not working accurately.
is there any solution or any method to do swipe back in flutter iOS web view.
currently i am trying to do this
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: primaryColor,
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
),
home: LocationCheck(),
),
);

I want to convert the code below into Cupertino, IOS style. But I Can't Use Drawer Menu for IOS style. Why? How can I use?

I want to make android and IOS style.
I want to convert the code below into Cupertino, IOS style.
But I Can't Use Drawer Menu for IOS style. Why?
How can I use?
return Scaffold(
key: _scaffoldKey,
drawer: Drawer(),
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_back_ios,
color: MyColors.blue,
),
),
centerTitle: true,
title: Text('Test', style: MyTextStyles.appBarTitle(deviceType) ),
actions: <Widget>[
Builder(
builder: (BuildContext context) => PlatformIconButton(
onPressed: () {
Scaffold.of(context).openDrawer();
},
icon: Icon(
Icons.menu,
)))])
body: .........
The Drawer widget is a Material-exclusive widget, and you can't use it directly on iOS.
You could build your own "Drawer-like" widget for iOS by replicating the build construction of a Drawer widget, but I would not recommend that, because drawers don't have that iOS "look and feel". As an iOS user myself, I know some very influential apps like Twitter have something that looks like a Drawer, but I think that is not the way a native iOS app would handle that kind of navigation.
What you can do instead, is having a Drawer widget for Android, and a bottom tab bar for iOS, which is a component that is way more common in iOS-styled apps. You can use the Platform class to check if your code is being executed on Android or iOS, and choose the right widget based on that.
Here is one example of such a build logic that you might find useful. I am very sorry I can't paste the code directly, I had this screenshot from a presentation I made and I don't remember where did I place the code for this project, but I hope you find it useful.

Flutter - Create own snackbar design

I want to create a Snackbar, that looks like an image below, Google has created. Something like this:
I wanted to start creating one, but I don't have an idea about it, how should I start or how should I customize the Snackbar. I don't want to use flutter toast plugin. I want to create my own Snackbar. It would be great if somebody guides me on this
First of all, based on your screenshot, maybe this is already supported by SnackBarBehavior, just pass the snackbar constructor behavior: SnackBarBehavior.floating, like this:
SnackBar(behavior: SnackBarBehavior.floating, content: ...)
If this is still not good enough, the best way to go about it is by starting with the SnackBar widget and customizing it. Though the widget's constructor parameters make the widget quite flexible, the SnackBar widget does not let you modify every little detail of it.
For example, I wanted to remove some padding in the snack bar and add some borders on the top, and at the time of this writing, this wasn't possible.
You should not modify directly the snack_bar.dart as it'll modify your local copy Flutter. Modifying snack_bar.dart directly has a couple of disadvantages:
All your local Flutter projects will have these modifications.
If you are in a team, nobody else will have these customizations.
If you use a "standard" CI/CD pipeline -as you only modified your local copy of Flutter-, the built apps will not have these customizations, nor does the released apps, obviously.
Upgrading Flutter (or changing channels) could be more difficult, as Flutter is using git (branches, commits) in the background for upgrading
The best solution for adding any complicated tweaks, implementing any customization to the SnackBar widget (apart from its public interface, of course) is to implement it.
class BetterSnackBar extends StatelessWidget implements SnackBar {
Widget build(BuildContext context) {
// Tweak the build method for maximum customization
}
// rest of the class, you can just copy-paste it
// from SnackBar, if you want to make sure you support
// everything the original snack bar supports
}
This way, you can still use your custom BetterSnackBar widget like the original for example, for showing it using the scaffold: Scaffold.of(context).showSnackBar(betterSnackBar);.
This solution also leaves your local Flutter copy untouched (other projects won't be affected by it, you can easily switch between Flutter channels and upgrade your Flutter version on your computer), meaning you can version control your project's BetterSnackBar (CI works, co-workers will see the changes).
If you want to achieve the floating look, with the nice animation sliding up from the bottom, you can do it manually, with a some customizations to the standard SnackBar implementation, without having to edit the source code of Flutter:
final snackBar = SnackBar(
backgroundColor: Colors.transparent,
elevation: 0,
content: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.greenAccent,
border: Border.all(color: Colors.green, width: 3),
boxShadow: const [
BoxShadow(
color: Color(0x19000000),
spreadRadius: 2.0,
blurRadius: 8.0,
offset: Offset(2, 4),
)
],
borderRadius: BorderRadius.circular(4),
),
child: Row(
children: [
const Icon(Icons.favorite, color: Colors.green ),
const Padding(
padding: EdgeInsets.only(left: 8.0),
child: Text('Yay! A SnackBar!\nYou did great!', style: TextStyle(color: Colors.green)),
),
const Spacer(),
TextButton(onPressed: () => debugPrint("Undid"), child: Text("Undo"))
],
)
),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
This wouldn't be a snackbar but it can work the same.
1) Create a view using LinearLayout, Relative, or Constraint that looks like the snack bar insdie of the page you want it on.
2) set the Visibility to Gone, or Invisible.
3) add onCLickListener to a button to make the Snackbar(the layout you just made) visible when the button is clicked.
EDIT: Warning!!!!!!! I check it and it change for all your projects, so I think it is not a really good option
Hello I have been trying doing the same as you, and the way that i found and can be helpful is edit the main snack_bar.dart file. You can access it by holding the control key and clicking on a Snackbar widget in the code.
After that just add this at the begining "import 'package:flutter/material.dart';" and change this:
child: Material(
elevation: 6.0,
color: _kSnackBackground,
child: Theme(
data: darkTheme,
child: mediaQueryData.accessibleNavigation ? snackbar : FadeTransition(
opacity: fadeAnimation,
child: snackbar,
),
),
),
for this:
child: Card(
elevation: 6.0,
color: _kSnackBackground,
child: Theme(
data: darkTheme,
child: mediaQueryData.accessibleNavigation ? snackbar : FadeTransition(
opacity: fadeAnimation,
child: snackbar,
),
),
),
And the result when you implement your snackbar going to be the next:

How to implement swipe to previous page in Flutter?

Go back feature works only on the edge of the screen on iPhone. How can I swipe to previous page from anywhere on the screen?
correct way is :
MaterialApp(
.
.
.
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
}
)
),
.
.
.
);
Use CupertinoPageRoute to make it work on Android.
If I understood correctly the problem is how to set custom width of the iOS back swipe gesture area?
So one of the possible solutions is to use this package: cupertino_back_gesture.
Explanation from authors of package:
To change width of area where the user can start back swipe for the whole app:
Wrap your MaterialApp with BackGestureWidthTheme with desired backGestureWidth
set iOS builder of pageTransitionsTheme to CupertinoPageTransitionsBuilderCustomBackGestureWidth
import 'package:cupertino_back_gesture/cupertino_back_gesture.dart';
BackGestureWidthTheme( backGestureWidth: BackGestureWidth.fraction(1 / 2), child: MaterialApp(
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilderCustomBackGestureWidth(),
},
),
),
home: MainPage(),
),
)
Example app can be found on github.com
Another solution is to use swipeable_page_rout. It has specific parameter onlySwipeFromEdge: false.
In materialApp simply set in theme
theme: ThemeData(
primarySwatch: Colors.green,
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
},
),
),
and where you are routing use CupertinoPageRoute instead of MaterialPageRoute it will work in right way .
You are most likely looking for PageView which allows swip to go next/previous page gesture.

Resources