Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this is updated code for textwidget #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// home_screen.dart
import 'package:flutter/material.dart';
import '/models/widget_model.dart';
import '/data/widget_data.dart';
import '/widgets/custom_text.dart'; // Import the custom Text widget.

class HomeScreen extends StatelessWidget {
@override
Expand All @@ -16,7 +16,31 @@ class HomeScreen extends StatelessWidget {
final widget = widgetData[index];
return ElevatedButton(
onPressed: () {
Navigator.pushNamed(context, '/widgetDetail', arguments: widget);
if (widget.name == 'Text') {
// Create and display the custom "Text" widget.
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(
title: Text(widget.name),
),
body: Center(
child: CustomText(
text: 'Hello, Custom Text!',
textStyle: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
),
),
),
);
} else {
// For other widgets, navigate to their respective detail screens.
Navigator.pushNamed(context, '/widgetDetail', arguments: widget);
}
},
child: Text(widget.name),
);
Expand Down
53 changes: 53 additions & 0 deletions lib/text/text.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';

class AnimatedCustomText extends StatefulWidget {
final String text;
final TextStyle textStyle;
final Duration animationDuration;

AnimatedCustomText({
required this.text,
this.textStyle = const TextStyle(),
this.animationDuration = const Duration(milliseconds: 500),
});

////
_AnimatedCustomTextState createState() => _AnimatedCustomTextState();
}

class _AnimatedCustomTextState extends State<AnimatedCustomText>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _opacityAnimation;

////
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: widget.animationDuration,
);
_opacityAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(_controller);


_controller.forward();
}

////
Widget build(BuildContext context) {
return AnimatedOpacity(
opacity: _opacityAnimation.value,
duration: widget.animationDuration,
child: Text(
widget.text,
style: widget.textStyle,
),
);
}

////
void dispose() {
_controller.dispose();
super.dispose();
}
}