AnimatedPhysicalModel example in Flutter

This Article is posted by seven.srikanth at 11/30/2022 4:39:15 AM



Here is an example for AnimatedPhysicalModel in flutter. 
Using AnimatedPhysicalModel, you can animate the shape of a container or other properties of a container. 
Below is how it's going to look. 
Here is the code from main.dart file. 

import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
  final title = 'AnimatedPhysicalModel example';
  @ override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: title,
      home: MyHomePage(
        title: title,
      ),
    );
  }
}
class MyHomePage extends StatefulWidget {
  final String title;
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  @ override
  State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  bool _first = true;
  @ override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: AnimatedPhysicalModel(
          borderRadius: BorderRadius.circular(!_first ? 0 : 100),
          duration: const Duration(seconds: 1),
          color: Colors.blue,
          elevation: !_first ? 20 : 40,
          shadowColor: !_first ? Colors.blue : Colors.red,
          shape: BoxShape.rectangle,
          child: const SizedBox(
            height: 150,
            width: 150,
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
          child: const Icon(Icons.transform),
          onPressed: () {
            setState(() {
              _first = !_first;
            });
          }),
    );
  }
}
Thanks,
Srikanth

Tags: AnimatedPhysicalModel








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com