Hi Guys, Welcome to Proto Coders Point, In this Tutorial Will be implement Hero Animation in flutter using a Widget Called Hero.
Hero Animation in Flutter Application Development
Hero Transition is a great to show an animation effect in flutter. They let’s the user know that they have changed the screens, while keeping the focus of the interaction.
Flutter has a widget called Hero,That will automatically create an hero animation transition effect between two navigation Routes.
Flutter will figure out the widget in both routes & animate the chnages that happens between the route locations.
Let’s suppose you have to show animation effect on a image in flutter app as your UI Hero Animation.
Put it on both the page screen routes.
The one that you’ll be transition from (MyHomePage.dart) and the one you’ll be transition to (Screen2.dart).
Then just you need to Wrap the Flutter Image Widget with a Here Widget on both the Pages.
Here in main.dart file i have created a Named routes from that i can easily Navigate from main.dart to Screen2.dart.
main.dart file have 2 main widgets that is a RaisedButton and an Hero widget that contains child as Container with in turn has a child with Widget Image.
as you can see in both the above pages codes that i have made user of Hero Widget that has a tag : ‘image’ with both the pages so that flutter can identify which widget should show Hero Animation
and All is set app is ready to show Hero Amination in your flutter app.
Create a fling animation effect using a physics simulation.
Code Snippet
AnimationController controller;
controller = AnimationController(
duration: Duration(seconds: 3),
vsync: this,
upperBound: 100.0,
);
controller.forward();
controller.addListener(() {
setState(() {
print(controller
.value); //used to just print controller value to see changes
});
});
Duration : The length of time this animation should last.
If [reverseDuration] is specified, then [duration] is only used when going [forward]. Otherwise, it specifies the duration going in both directions.
vsync : this
package:flutter/src/widgets/ticker_provider.dart mixin SingleTickerProviderStateMixin<T extends StatefulWidget> on State<T> implements TickerProvider
Provides a single [Ticker] that is configured to only tick while the current tree is enabled, as defined by [TickerMode].
To create the [AnimationController] in a [State] that only uses a single [AnimationController], mix in this class, then pass vsync: this to the animation controller constructor.
This mixin only supports vending a single ticker. If you might have multiple [AnimationController] objects over the lifetime of the [State], use a full [TickerProviderStateMixin] instead.
In the above flutter animation i have simply gave an anim effect to an image where an image size gets increase within 3 seconds from Container height 0 to 100.
Here i am setting the container height from 0 – 100 in 3 seconds.
1. Flutter Animation Effect Example 1
Copy paste the Below lines of code in main.dart file of you animation project
But this animation will continue forever unless we trash the controller.
Even if this screen is dismissed that Controller will still be running and will make user of mobile memory or resources. So whenever you’re using animation controller in you project it’s really important that you tap it into dispose method.
Hi Guys welcome to Proto Coders Point, In the Tutorial, we will learn about the Flutter widget class i.e Rich Text.
Introduction to Flutter RichText widget
In Flutter, RichText is used to display multiply text styles.
Here, the text to be displayed is done using TextSpan objects.
The text which is displayed in the rich text widget should be styled explicitly. you can set a DefaultTextStyle using the current BuildContext to provide defaults. To learn more on how to style text in RichText Widget. see the documentation for TextStyle.
Implementation of Flutter Rich Text Example
ok, So we now know the basic of the above Flutter Text Widget. It’s time to implement the widget in our project. For that, we need to first create a new Flutter Project or you can continue with your existing one.
File > New > New Flutter Project
If you can’t find any option to create a flutter project that might be because you have not installed the flutter plugin into your android studio.
Check out this post to install flutter in android studio.
Hi Guys, Welcome to Proto Coders Point In this Tutorial we will learn how to parse json data in dart ( flutter ) language.
Before that if you are new in json and want to learn basic of json read this.
What is JSON Data ?
JSON stands for JAVASCRIPT OBJECT NOTATION , it’s an lightweight formated data for storing and transporting data very fast, JSON data are often used when data is to be sent from server to any application. Json is very easy for human being to read as it stored in text format.
Dart language has a built-in support for parsing json data.
You can easily convert json data into String using dart:convert library and map it with key: value parse, where keys are string and value are of dynamic objects.
import 'dart:convert';
You need to import dart:convert to convert json data.
Direct Json Parsing and How to use the data
var jsonData = '{ "name" : "ProtoCodersPoint", "website" : "protocoderspoint.com" }'; //simple json data
var parsedJson = json.decode(jsonData); // need to import convert library
print('${parsedJson.runtimeType} : $parsedJson'); //Display full json Parse
print(parsedJson['name']); //fetch value using key 'name'
print(parsedJson['website']); // fetch value using key 'website'
Then, after Executing the above code you will get output like:
Ok So you can play with the json data using its key index, as you can see i m printing the data using it’s key in above lines of code.
Then, Instead of using json Parser directly, it’s better to pass the json data to a class that handles your data from you. This can be done using a constructor in flutter dart.
class UserData {
String name;
String website;
UserData(Map<String, dynamic> data) {
name = data['name'];
website = data['website'];
}
}
Here I have defined an external class that will handle out json parser data, I have made use of Map which has datatypes as Map<String,dynamic>.
var jsonData = '{ "name" : "Welcome", "website" : "protocoderspoint.com" }'; //simple json data
var parsedJson = json.decode(jsonData); // need to import convert library
UserData userData = UserData(parsedJson); // creating an object and passed parsed JSON data
print("${userData.name} Keep learning from ${userData.website}");
Here i have parsed Json data using json.decode and then Created a class object names userData and passed parsed json data to class constructor.
Complete Code of parsing json data in flutter dart programming
Create a Flutter project in android-studio and copy paste the below lines of parse json in flutter code main.dart file
main.dart
import 'package:flutter/material.dart';
import 'dart:convert';
void main() => runApp(MyApp());
String Welcome = "";
String website = " ";
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
var jsonData =
'{ "name" : "Welcome", "website" : "protocoderspoint.com" }'; //simple json data
var parsedJson = json.decode(jsonData); // need to import convert library
UserData userData = UserData(parsedJson);
Welcome = userData.name;
website = userData.website;
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("JSON PARSE DEMO"),
),
body: Center(
child: Text("${Welcome} keep Learning from ${website}"),
),
);
}
}
class UserData {
String name;
String website;
UserData(Map<String, dynamic> data) {
name = data['name'];
website = data['website'];
}
}
Hello Guys, Welcome to Proto Coders Point, In this Android Article we will implement an android GitHub library called Ripple-backgroundused to give device searching or ‘ripple animation android effect’
Which is the Ripple Effect Background?
An Android Ripple Background Github Library that provide an app with an beautiful ripple animation android.
To Learn in detail of this library visit official github site
This Beautiful Ripple background library is been created by Jason Yu Check out his other library they are an awesome android library and very easy to use and understand here
Demo of Ripple Searching device UI
Searching Device an Ripple Background animation gif
Before we start implementing this library, I just want to say that in this tutorial we are simply Createing a ripple wave backgroud UI(User Interface), This tutorial will not actually search or find real time actual device near by.
So let’s begin adding some required staff into our project.
I assume that you have already created a new android project in your android-studio or you may also add this library in your existing project, all left to you it your choice.
Adding Dependencies in our project
Now, you to add library depencencies in your project. Open build.gradle(module: app)