import 'package:flutter/material.dart';
import 'package:animated_text_kit/animated_text_kit.dart';
import "dart:convert";
import 'package:http/http.dart' as http;
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Stateful Clicker Counter';
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
theme: ThemeData(
primarySwatch: Colors.deepOrange,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String? catFact;
Future<void> fetchCatFact() async {
var response = await http.get(Uri.parse("https://catfact.ninja/fact"));
if (response.statusCode == 200) {
var data = json.decode(response.body);
setState(() {
catFact = data["fact"];
});
} else {
print("hey something is wrong, sorry!");
}
}
@override
void initState() {
// TODO: implement initState
super.initState();
fetchCatFact();
}
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: [
DrawerHeader(
decoration: BoxDecoration(
color: Colors.orange,
),
child: Column(
children: [
Text("Settings"),
Container(
width: 100,
child: Image.network(
"https://static.vecteezy.com/system/resources/thumbnails/021/830/103/small/realistic-cute-cat-cartoon-style-digital-artwork-free-png.png"),
)
],
),
),
ListTile(
title: const Text('Cats'),
onTap: () {},
),
ListTile(
title: const Text('Settings'),
onTap: () {},
),
],
),
),
appBar: AppBar(
title: Text("Summer School h-farm"),
backgroundColor: Colors.deepOrangeAccent,
),
body: Column(
children: [
Container(
height: 200,
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
//decoration for the outer wrapper
color: Colors.deepOrangeAccent,
borderRadius: BorderRadius.circular(
30), //border radius exactly to ClipRRect
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5), //color of shadow
spreadRadius: 5, //spread radius
blurRadius: 7, // blur radius
offset: Offset(0, 2), // changes position of shadow
//first paramerter of offset is left-right
//second parameter is top to down
),
//you can set more BoxShadow() here
],
),
child: ClipRRect(
//to clip overflown positioned containers.
borderRadius: BorderRadius.circular(30),
//if we set border radius on container, the overflown content get displayed at corner.
child: Container(
child: Stack(
children: <Widget>[
//Stack helps to overlap widgets
Positioned(
//positioned helps to position widget wherever we want.
top: -20,
left: -50, //position of the widget
child: Container(
height: 250,
width: 250,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.orange.withOpacity(
0.5) //background color with opacity
))),
Positioned(
left: -80,
top: -50,
child: Container(
height: 180,
width: 180,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.redAccent.withOpacity(0.5)))),
Positioned(
//main content container postition.
child: Container(
height: 250,
alignment: Alignment.center,
child: CircleAvatar(
radius: 80.0,
backgroundImage: NetworkImage(
"https://static.vecteezy.com/system/resources/thumbnails/021/830/103/small/realistic-cute-cat-cartoon-style-digital-artwork-free-png.png"),
backgroundColor: Colors.transparent,
)),
),
Positioned(
left: 110,
top: 170,
child: Text(
"Cats Fun Facts",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.white),
)),
],
)),
),
),
catFact == null
? CircularProgressIndicator()
: Container(
padding: EdgeInsets.all(8),
height: 200,
width: 350,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(color: Colors.orangeAccent, width: 3)),
child: AnimatedTextKit(
key: ValueKey(catFact),
animatedTexts: [
TypewriterAnimatedText(
catFact!,
textStyle: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.grey),
speed: const Duration(milliseconds: 80),
),
],
totalRepeatCount: 1,
pause: const Duration(milliseconds: 1),
displayFullTextOnTap: true,
stopPauseOnTap: true,
),
),
SizedBox(
height: 100,
),
TextButton.icon(
onPressed: fetchCatFact,
icon: Icon(Icons.catching_pokemon, size: 35),
label: Text("Click me", style: TextStyle(fontSize: 24)),
)
],
),
);
}
}