Execute animation when button clicked flutter - flutter

I am creating a flutter web where is created home and about widget in column and uses SlideTransition on about widget but the thing is when the page load the animation happen even I am on Home widget.
I want when i click on about widget then the animation will occur not at the start of page.
how to do that?
Here is my code:
class MainPage extends StatefulWidget {
const MainPage({super.key});
#override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> with TickerProviderStateMixin {
bool aboutClick = false;
bool servicesClick = false;
bool contactClick = false;
final fname = TextEditingController();
final lname = TextEditingController();
final email = TextEditingController();
final phoneNo = TextEditingController();
final message = TextEditingController();
final emailVerificationSyntax = RegExp(
r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+#[a-zA-Z0-9]+\.[a-zA-Z]+");
final homeKey = GlobalKey();
final aboutKey = GlobalKey();
final servicesKey = GlobalKey();
final contactKey = GlobalKey();
AnimationController? animationController;
Animation<Offset>? _animationValue;
#override
void initState() {
super.initState();
animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
)..forward();
_animationValue = Tween<Offset>(
begin: const Offset(-0.5, 0.0), end: const Offset(0.0, 0.0))
.animate(
CurvedAnimation(
parent: animationController!,
curve: Curves.easeIn,
),
);
// animationController!.addStatusListener((status) {
// if (status == AnimationStatus.completed) {
// animationController!.reverse();
// } else if (status == AnimationStatus.dismissed) {
// animationController!.forward();
// }
// });
// animationController!.forward();
}
#override
void dispose() {
animationController!.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return MediaQuery.of(context).size.width <= 910
? const MobileMainPage()
: Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
toolbarHeight: 100,
flexibleSpace: Container(
color: Colors.black,
width: double.infinity,
height: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
RichText(
textScaleFactor: 1.3,
text: const TextSpan(
style: TextStyle(
color: Colors.black,
fontSize: 25,
),
children: <TextSpan>[
TextSpan(
text: "Rizwan",
style: TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.bold,
fontFamily: "Joining",
),
),
TextSpan(
text: " •",
style: TextStyle(
fontSize: 50,
color: Colors.green,
fontWeight: FontWeight.bold,
fontFamily: "Joining",
),
),
],
),
),
Row(
children: [
TextButton(
onPressed: () {
Scrollable.ensureVisible(homeKey.currentContext!,
duration: const Duration(seconds: 2),
curve: Curves.ease);
},
style: TextButton.styleFrom().copyWith(
animationDuration:
const Duration(milliseconds: 300),
textStyle: MaterialStateProperty.resolveWith(
(states) {
if (states.contains(MaterialState.hovered)) {
return const TextStyle(
fontSize: 35,
);
}
return const TextStyle(
fontSize: 30,
);
},
),
foregroundColor:
MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.hovered)) {
return Colors.green;
}
return Colors.white;
})),
child: const Text(
"Home",
style: TextStyle(
fontFamily: "Simple",
),
),
),
const SizedBox(
width: 10,
),
TextButton(
onPressed: () {
Scrollable.ensureVisible(aboutKey.currentContext!,
duration: const Duration(seconds: 2),
curve: Curves.ease);
setState(() {
aboutClick = true;
});
},
style: TextButton.styleFrom().copyWith(
animationDuration:
const Duration(milliseconds: 300),
textStyle: MaterialStateProperty.resolveWith(
(states) {
if (states.contains(MaterialState.hovered)) {
return const TextStyle(
fontSize: 35,
);
}
return const TextStyle(
fontSize: 30,
);
},
),
foregroundColor:
MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.hovered)) {
return Colors.green;
}
return Colors.white;
})),
child: const Text(
"About",
style: TextStyle(
fontFamily: "Simple",
),
),
),
],
),
],
),
),
),
body: SingleChildScrollView(
child: Column(
children: [
homeWidget(homeKey),
aboutWidget(aboutKey, _animationValue),
servicesWidget(servicesKey),
contactWidget(contactKey, fname, lname, email, phoneNo,
message, emailVerificationSyntax)
],
),
),
);
}
homeWidget(GlobalKey<State<StatefulWidget>> homeKey) {
return Row(
key: homeKey,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 160,
),
const Text(
"Hi, I am",
style: TextStyle(
color: Colors.white,
fontSize: 60,
fontWeight: FontWeight.bold),
),
const SizedBox(
height: 10,
),
const Text(
"RIZWAN ALI",
style: TextStyle(
color: Colors.white,
fontSize: 70,
fontWeight: FontWeight.bold,
fontFamily: "Shade",
),
),
const SizedBox(
height: 10,
),
DefaultTextStyle(
style: const TextStyle(
fontSize: 30.0,
fontWeight: FontWeight.bold,
color: Colors.grey),
child: AnimatedTextKit(
pause: const Duration(seconds: 1),
repeatForever: true,
animatedTexts: [
TypewriterAnimatedText(
'Flutter Developer',
speed: const Duration(
milliseconds: 90,
),
curve: Curves.linear,
),
TypewriterAnimatedText(
'Android Native Developer',
speed: const Duration(
milliseconds: 90,
),
curve: Curves.linear,
),
TypewriterAnimatedText(
'Web Developer',
speed: const Duration(
milliseconds: 90,
),
curve: Curves.linear,
),
TypewriterAnimatedText(
'Freelancer',
speed: const Duration(
milliseconds: 90,
),
curve: Curves.linear,
),
TypewriterAnimatedText(
'Photographer',
speed: const Duration(
milliseconds: 90,
),
curve: Curves.linear,
),
TypewriterAnimatedText(
'Cricketer',
speed: const Duration(
milliseconds: 90,
),
curve: Curves.linear,
),
],
),
),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(20),
shape: const StadiumBorder(),
backgroundColor: Colors.green,
),
child: const Text(
"Download CV",
style: TextStyle(
fontSize: 40,
),
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 70.0),
child: Container(
width: 450,
height: 450,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("me.jpg"),
fit: BoxFit.cover,
),
shape: BoxShape.circle,
),
),
),
],
);
}
aboutWidget(GlobalKey<State<StatefulWidget>> aboutKey,
Animation<Offset>? animationValue) {
return SlideTransition(
position: animationValue!,
child: Padding(
key: aboutKey,
padding: const EdgeInsets.only(top: 80.0),
child: SizedBox(
height: 600,
width: double.infinity,
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
"ABOUT",
style: TextStyle(
color: Colors.white,
fontSize: 35,
fontWeight: FontWeight.bold,
fontFamily: "Simple",
),
),
const SizedBox(
height: 20,
),
SizedBox(
width: 700,
height: 100,
child: Wrap(
children: const [
Text(
"I'm a Flutter and Android Native Developer building Applications that leads to the success of the overall product. Check out some of my work in the Work section. I also like sharing content related to the stuff that I have learned in Flutter Development so it can help other people of the Dev Community. Feel free to Connect or Follow me on my Linkedin where I post useful content related to Web Development and Programming. I'm open to Job opportunities where I can contribute, learn and grow. If you have a good opportunity that matches my skills and experience then don't hesitate to contact me.",
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
textAlign: TextAlign.center,
)
],
),
),
const SizedBox(
height: 120,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 40,
height: 40,
decoration: const BoxDecoration(
color: Color.fromARGB(221, 49, 40, 40),
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
child: Center(
child: Container(
width: 15,
height: 15,
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
),
),
),
const SizedBox(
width: 200,
),
Container(
width: 40,
height: 40,
decoration: const BoxDecoration(
color: Color.fromARGB(221, 49, 40, 40),
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
child: Center(
child: Container(
width: 15,
height: 15,
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
),
),
),
const SizedBox(
width: 200,
),
Container(
width: 40,
height: 40,
decoration: const BoxDecoration(
color: Color.fromARGB(221, 49, 40, 40),
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
child: Center(
child: Container(
width: 15,
height: 15,
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
),
),
),
const SizedBox(
width: 200,
),
Container(
width: 40,
height: 40,
decoration: const BoxDecoration(
color: Color.fromARGB(221, 49, 40, 40),
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
child: Center(
child: Container(
width: 15,
height: 15,
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
),
),
),
],
),
const SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
"Name",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 200,
),
Text(
"Email",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 180,
),
Text(
"Linkedin",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 180,
),
Text(
"Phone",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
),
],
),
const SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
width: 20,
),
const Text(
"RIZWAN ALI",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
const SizedBox(
width: 90,
),
const Text(
"rizwanali96960#gmail.com",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
const SizedBox(
width: 50,
),
TextButton(
onPressed: () async {
final url = Uri.parse(
"https://www.linkedin.com/in/rizwan-ali-361514212");
if (await canLaunchUrl(url)) {
await launchUrl(
url,
);
}
},
child: const Text(
"Linkedin-Profile",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
),
const SizedBox(
width: 90,
),
const Text(
"+92 307 4500296",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
],
),
const SizedBox(
height: 45,
),
ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(15),
shape: const StadiumBorder(),
backgroundColor: Colors.green,
),
child: const Text(
"LET'S TALK",
style: TextStyle(
fontSize: 35,
),
),
),
],
),
),
),
),
);
}

You should not start the animation during initState, if you don't want the animation to play right away.
In your code:
void initState() {
super.initState();
animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
)..forward(); // <----- REMOVE THIS PART
In your code above, you should remove the ..forward() during the initialization. This will prevent it to run at the start of the page.
Next, in the button click event, you can call animationController.forward() and it should begin the animation. You can also specify a starting point, e.g. animationController.forward(from: 0), to ensure the animation always starts at the very beginning.

Related

Flutter GridView Item Selection Color Change (on tap)

I have created a GridView, and the next step I'm trying to achieve is changing the color of the container when it is tapped/ selected. When I try and do it with both Inkwell and GestureDetector, it changes the color of both containers in the row, rather than changing each one individually. I want to have each container change colors when it is tapped, as well as have a check mark appear on the corner:
(1) My Layout
(2) Example of what I want
I'm very new to Flutter, so I know that the way that I've coded my layout is far from optimal. I'm attaching a small chunk of just the GridView portion to show how I created the GridView (basically, I created 6 containers all with varying custom icons and text). Hopefully I'll receive some assistance :).
Updated June 21st:
class SelectionPage extends StatefulWidget {
const SelectionPage({Key? key}) : super(key: key);
#override
_SelectionPageState createState() => _SelectionPageState();
}
class Item{
String title;
bool isSelected;
Item({required this.title, this.isSelected = false});
List <Item>listOfModel = [];
listOfModel.add(Item(title: "Maintaining healthy relationships"));
listOfModel.add(Item(title: "Being happier and more content in life"));
}
class _SelectionPageState extends State<SelectionPage>{
Color _ContainerColor = Colors.white;
#override
Widget build(BuildContext) {
double _height = MediaQuery.of(context).size.height;
final data = ModalRoute.of(context)!.settings;
late String retrieveString;
if (data.arguments == null)
retrieveString = "empty";
else
retrieveString = data.arguments as String;
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: const Color(0xff31708c),
body: Padding(
padding: EdgeInsets.only(
left: 30,
right: 30,
top: _height * 0.2),
child: Column(
children: <Widget>[
Text('Hello there $data! What all would you like to focus on? You can pick all that apply:',
style: GoogleFonts.montserrat(
color: Colors.white70,
fontSize: 19,
fontWeight: FontWeight.w600
),
textAlign: TextAlign.center,),
const SizedBox(height: 12,),
Column(children: [
GridView.count(
primary: true,
shrinkWrap: true,
padding: const EdgeInsets.all(10),
childAspectRatio: 1.15,
crossAxisCount: 2,
crossAxisSpacing: 25,
mainAxisSpacing: 25,
children: <Widget>[
GestureDetector(
onTap: () {
setState(() {
_ContainerColor = _ContainerColor == Colors.white
? Color(0xffa1d0e6)
: Colors.white;
});
},
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color.fromARGB(255, 20, 83, 106),
width: 2.5),
color: _ContainerColor
),
child: Column(
children: [
const Align(alignment: Alignment.topCenter,
child: Icon(MyFlutterApp.relationships,
color: Color(0xff31708c),
size: 45,),
),
const SizedBox(height: 4,),
Text('Maintaining healthy relationships',
style: GoogleFonts.montserrat(
fontSize: 14,
fontWeight: FontWeight.w500,
color: const Color(0xff31708c)
),
textAlign: TextAlign.center,)
],
),
),
),
GestureDetector(
onTap: () {
setState(() {
_ContainerColor = _ContainerColor == Colors.white
? Color(0xffa1d0e6)
: Colors.white;
});
},
child: Container(
padding: const EdgeInsets.all(13.5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color.fromARGB(255, 20, 83, 106),
width: 2.5),
color: Colors.white
),
child: Column(
children: [
const Align(alignment: Alignment.topCenter,
child: Icon(MyFlutterApp.happy,
color: Color(0xff31708c),
size: 30,),
),
const SizedBox(height: 12,),
Text('Being happier and more content in life',
style: GoogleFonts.montserrat(
fontSize: 14,
fontWeight: FontWeight.w500,
color: const Color(0xff31708c)
),
textAlign: TextAlign.center,)
],
),
),
),
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color.fromARGB(255, 20, 83, 106),
width: 2.5),
color: Colors.white
),
child: Column(
children: [
const Align(alignment: Alignment.topCenter,
child: Icon(MyFlutterApp.balance,
color: Color(0xff31708c),
size: 40,),
),
const SizedBox(height: 8,),
Text('Maintaining a better work-life balance',
style: GoogleFonts.montserrat(
fontSize: 14,
fontWeight: FontWeight.w500,
color: const Color(0xff31708c)
),
textAlign: TextAlign.center,)
],
),
),
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color.fromARGB(255, 20, 83, 106),
width: 2.5),
color: Colors.white
),
child: Column(
children: [
const Align(alignment: Alignment.topCenter,
child: Icon(MyFlutterApp2.personal_growth,
color: Color(0xff31708c),
size: 35,),
),
const SizedBox(height: 10,),
Text('Personal growth and development',
style: GoogleFonts.montserrat(
fontSize: 14,
fontWeight: FontWeight.w500,
color: const Color(0xff31708c)
),
textAlign: TextAlign.center,)
],
),
),
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color.fromARGB(255, 20, 83, 106),
width: 2.5),
color: Colors.white
),
child: Column(
children: [
const Align(alignment: Alignment.topCenter,
child: Icon(MyFlutterApp2.meditate,
color: Color(0xff31708c),
size: 45,),
),
const SizedBox(height: 4,),
Text('Stress and anxiety management',
style: GoogleFonts.montserrat(
fontSize: 14,
fontWeight: FontWeight.w500,
color: const Color(0xff31708c)
),
textAlign: TextAlign.center,)
],
),
),
Container(
padding: const EdgeInsets.all(11),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color.fromARGB(255, 20, 83, 106),
width: 2.5),
color: Colors.white
),
child: Column(
children: [
const Align(alignment: Alignment.topCenter,
child: Icon(MyFlutterApp3.well_rounded,
color: Color(0xff31708c),
size: 37,),
),
const SizedBox(height: 10,),
Text('Mental and emotional well-being',
style: GoogleFonts.montserrat(
fontSize: 14,
fontWeight: FontWeight.w500,
color: const Color(0xff31708c)
),
textAlign: TextAlign.center,)
],
),
),
],
),]),
const SizedBox(height: 17,),
ElevatedButton(
onPressed: () {
Navigator.push(context,
PageTransition(
type: PageTransitionType.bottomToTop,
duration: const Duration(milliseconds: 650),
child: const LoginScreen2() // CHANGE THIS AS SOON AS YOU CAN FIGURE SOMETHING OUT
));
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 88,
vertical: 16),
primary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50)
)
),
child: Text(
'Continue',
style: GoogleFonts.montserrat(
color: const Color.fromARGB(255, 20, 83, 106),
fontSize: 19,
fontWeight: FontWeight.w600
),
),)
],
),
),
);
}
}
Hey you can create a model with 2 variables String title and bool isSelected. If you need you can add icon in item model also -
See below updated code-
class SelectionPage extends StatefulWidget {
const SelectionPage({Key? key}) : super(key: key);
#override
_SelectionPageState createState() => _SelectionPageState();
}
class _SelectionPageState extends State<SelectionPage>{
// Color _ContainerColor = Colors.white;
late String retrieveString;
List <Item>listOfModel = [];
#override
void initState() {
final data = ModalRoute.of(context)!.settings;
if (data.arguments == null) {
retrieveString = "empty";
} else {
retrieveString = data.arguments as String;
}
listOfModel.add(Item(title: "Maintaining healthy relationships"));
listOfModel.add(Item(title: "Being happier and more content in life"));
super.initState();
}
#override
Widget build(BuildContext context) {
double _height = MediaQuery.of(context).size.height;
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: const Color(0xff31708c),
body: Padding(
padding: EdgeInsets.only(
left: 30,
right: 30,
top: _height * 0.2),
child: Column(
children: <Widget>[
Text('Hello there $data! What all would you like to focus on? You can pick all that apply:',
style: GoogleFonts.montserrat(
color: Colors.white70,
fontSize: 19,
fontWeight: FontWeight.w600
),
textAlign: TextAlign.center,),
const SizedBox(height: 12,),
GridView.count(
primary: true,
shrinkWrap: true,
padding: const EdgeInsets.all(10),
childAspectRatio: 1.15,
crossAxisCount: 2,
crossAxisSpacing: 25,
mainAxisSpacing: 25,
children: [
gridItem(listOfModel[0],MyFlutterApp.relationships ),
gridItem(listOfModel[1],MyFlutterApp.relationships ),
],
),
const SizedBox(height: 17,),
ElevatedButton(
onPressed: () {
Navigator.push(context,
PageTransition(
type: PageTransitionType.bottomToTop,
duration: const Duration(milliseconds: 650),
child: const LoginScreen2() // CHANGE THIS AS SOON AS YOU CAN FIGURE SOMETHING OUT
));
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 88,
vertical: 16),
primary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50)
)
),
child: Text(
'Continue',
style: GoogleFonts.montserrat(
color: const Color.fromARGB(255, 20, 83, 106),
fontSize: 19,
fontWeight: FontWeight.w600
),
),)
],
),
),
);
}
Widget gridItem(Item item, IconData icon){
return GestureDetector(
onTap: () {
setState(() {
item.isSelected = !item.isSelected;
});
},
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color.fromARGB(255, 20, 83, 106),
width: 2.5),
color: item.isSelected ? const Color(0xffa1d0e6) : Colors.white
),
child: Column(
children: [
Align(alignment: Alignment.topCenter,
child: Icon(
icon,
color: const Color(0xff31708c),
size: 45,
),
),
const SizedBox(height: 4,),
Text(item.title,
style: GoogleFonts.montserrat(
fontSize: 14,
fontWeight: FontWeight.w500,
color: const Color(0xff31708c)
),
textAlign: TextAlign.center,)
],
),
),
);
}
}
class Item{
String title;
bool isSelected;
Item({required this.title, this.isSelected = false});
}

NavigationBar is imported from both 'package:flutter/src/material/navigation_bar.dart' and 'package:flutter_onboarding_slider/navigation_bar.dart'

**i am facing error while running error is this because of packges or something else i have remove all the old code and add new still facing following error.
Error: 'NavigationBar' is imported from both 'package:flutter/src/material/navigation_bar.dart' and 'package:flutter_onboarding_slider/navigation_bar.dart'.
appBar: NavigationBar(
^^^^^^^^^^^^^
: Warning: Operand of null-aware operation '?.' has type 'GoogleMapController' which excludes null.
lib/…/map/map.dart:62
'GoogleMapController' is from 'package:google_maps_flutter/google_maps_flutter.dart' ('/D:/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter-2.1.7/lib/google_maps_flutter.dart').
package:google_maps_flutter/google_maps_flutter.dart:1
_controller?.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
^
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_onboarding_slider/flutter_onboarding_slider.dart';
import 'package:fyppedometer/mainScreens/Navigation/navigationBar.dart';
import 'package:fyppedometer/widgets/constants.dart';
import 'package:fyppedometer/widgets/text.dart';
class MyHome extends StatefulWidget {
const MyHome({Key? key}) : super(key: key);
#override
State<MyHome> createState() => _MyHomeState();
}
class _MyHomeState extends State {
final Color kDarkBlueColor = Colors.cyan;
// ignore: non_constant_identifier_names
List<String> numbers_Height = [
for (var i = 1.1; i <= 10.0; i = i + 0.1) i.toString()
];
// ignore: non_constant_identifier_names
List<String> numbers_Weight = [for (var i = 1; i <= 1000; i++) i.toString()];
int _groupValue = -1;
String _selectedGender = 'male';
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
// color: Colors.amber,
child: OnBoardingSlider(
buttonText: 'Start',
onFinish: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => Navbar(),
),
);
},
buttonTextColor: Colors.cyan,
// skipTextButton: Text(
// 'Skip',
// style: TextStyle(
// fontSize: 16,
// color: kDarkBlueColor,
// fontWeight: FontWeight.w600,
// ),
// ),
// trailing: Text(
// 'Login',
// style: TextStyle(
// fontSize: 16,
// color: kDarkBlueColor,
// fontWeight: FontWeight.w600,
// ),
// ),
// trailingFunction: () {
// // Navigator.push(
// // context,
// // CupertinoPageRoute(
// // builder: (context) => LoginPage(),
// // ),
// // );
// },
controllerColor: kDarkBlueColor,
totalPage: 3,
headerBackgroundColor: liteblue,
pageBackgroundColor: liteblue,
background: [
Padding(
padding: const EdgeInsets.only(top: 210, left: 80),
child: Image.asset(
'assets/gender.png',
height: MediaQuery.of(context).size.height * 0.6,
width: MediaQuery.of(context).size.width * 0.6,
),
),
Padding(
padding: const EdgeInsets.only(top: 160, left: 60),
child: Image.asset(
'assets/walking.png',
height: MediaQuery.of(context).size.height * 0.7,
width: MediaQuery.of(context).size.width * 0.7,
),
),
Padding(
padding: const EdgeInsets.only(top: 200, left: 60),
child: Image.asset(
'assets/human.png',
height: MediaQuery.of(context).size.height * 0.6,
width: MediaQuery.of(context).size.width * 0.6,
),
),
],
speed: 1.8,
pageBodies: [
Container(
// padding: EdgeInsets.symmetric(horizontal: 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Text(
'What’s Your Gender',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
const Text(
'Calories & Stride length calculation need it ',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white60,
fontSize: 21.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: size.height * 0.1,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(25), // radius of 10
color: Color.fromARGB(255, 19, 65, 103),
),
child: Center(
child: ListTile(
leading: Radio<String>(
activeColor: Colors.white,
value: 'male',
groupValue: _selectedGender,
onChanged: (value) {
setState(() {
_selectedGender = value!;
});
},
),
title: text(
textData: "Male",
color: Colors.white,
fontsize: 20.0,
fontweight: FontWeight.bold),
// Text(_selectedGender == 'male' ? 'Hello gentlement!' : 'Hi lady!')
),
),
),
SizedBox(height: 20),
Container(
height: size.height * 0.1,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(25), // radius of 10
color: Color.fromARGB(255, 19, 65, 103),
),
child: Center(
child: ListTile(
leading: Radio<String>(
activeColor: Colors.white,
value: 'female',
groupValue: _selectedGender,
onChanged: (value) {
setState(() {
_selectedGender = value!;
});
},
),
title: text(
textData: "Female",
color: Colors.white,
fontsize: 20.0,
fontweight: FontWeight.bold),
// Text(_selectedGender == 'male' ? 'Hello gentlement!' : 'Hi lady!')
),
),
),
],
)
]),
),
Container(
// padding: EdgeInsets.symmetric(horizontal: 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Text(
'How Tall are you?',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 28.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
const Text(
'To Personalize Your Fitness Goal ',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white60,
fontSize: 20.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Container(
height: size.height * 0.10,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Color.fromARGB(255, 145, 174, 225))),
child: Center(
child: text(
textData: "Height",
fontsize: 30.0,
fontweight: FontWeight.bold,
color: Color.fromARGB(255, 147, 148, 152)),
),
),
),
SizedBox(
height: 30,
),
Center(
child: Container(
height: size.height * 0.13,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Color.fromARGB(255, 92, 89, 89)),
// color: Colors.white,
),
child: ListWheelScrollView.useDelegate(
itemExtent: 100,
// controller: fixedExtentScrollController,
physics: FixedExtentScrollPhysics(),
onSelectedItemChanged: (i) {
print(numbers_Height[i]);
},
childDelegate: ListWheelChildLoopingListDelegate(
children: <Widget>[
...numbers_Height.map((String number) {
return Center(
child: Text(
number,
style: const TextStyle(
fontSize: 28.0,
color: Colors.white,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none),
),
);
})
],
),
),
),
)
],
)
]),
),
Container(
// padding: EdgeInsets.symmetric(horizontal: 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Text(
'How much do you Weight?',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 28.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
const Text(
'To Personalize Your Fitness Goal ',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white60,
fontSize: 20.0,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Container(
height: size.height * 0.10,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Color.fromARGB(255, 145, 174, 225))),
child: Center(
child: text(
textData: "Weight",
fontsize: 30.0,
fontweight: FontWeight.bold,
color: Color.fromARGB(255, 147, 148, 152)),
),
),
),
SizedBox(
height: 30,
),
Center(
child: Container(
height: size.height * 0.13,
width: size.width * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Color.fromARGB(255, 92, 89, 89)),
),
child: ListWheelScrollView.useDelegate(
itemExtent: 100,
physics: FixedExtentScrollPhysics(),
onSelectedItemChanged: (i) {
print(numbers_Weight[i]);
},
childDelegate: ListWheelChildLoopingListDelegate(
children: <Widget>[
...numbers_Weight.map((String number) {
return Center(
child: Text(
number, //Here is the child value I would like to get
style: const TextStyle(
fontSize: 28.0,
color: Colors.white,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none),
),
);
})
],
),
),
),
)
],
)
]),
),
],
),
);
}
}
Use show and hide to import part of a library.
// Import only foo.
import 'package:lib1/lib1.dart' show foo;
// Import all names EXCEPT foo.
import 'package:lib2/lib2.dart' hide foo;
See Using libraries for details.

flutter problem: dataColumn width issue and How to remove rowDivider from dataTable?

here i got width issue for data table and I also want every rowDivider will be remove,
and here I use animation, if you have any idea to improve animation then tell me.
here i got width issue for data table and I also want every rowDivider will be remove,
and here I use animation, if you have any idea to improve animation then tell me.
this is my full code
import 'package:bonanza_flutter/Constants/constants.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
double _height = 60.0;
bool _isExpanded = false;
Future<bool> _showList() async {
await Future.delayed(Duration(milliseconds: 300));
return true;
}
Future<bool> _showList1() async {
await Future.delayed(Duration(milliseconds: 10));
return true;
}
bool isOnPMS = true;
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
),
body: SingleChildScrollView(
child: Column(
children: [
// imageSlider(),
pmsData(),
// advantages(),
// products(),
Container(
height: 20,
)
],
),
),
);
}
}
extension WidgetExtension on _HomePageState {
pmsData() {
return Container(
color: lightBlue,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(20.0),
child: Column( crossAxisAlignment: CrossAxisAlignment.start,children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"PMS",
style:
TextStyle(fontSize: tSize16, fontWeight: FontWeight.w500),
),
Row(
children: [
Container(
width: 22,
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: skyBlue,
),
child: Icon(
Icons.arrow_back_ios_outlined,
color: Colors.white,
size: 17,
),
),
SizedBox(
width: 20,
),
Container(
width: 22,
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: skyBlue,
),
child: Icon(
Icons.arrow_forward_ios_rounded,
color: Colors.white,
size: 17,
),
),
],
)
],
),
SizedBox(
height: 8,
),
Text(
"ICICI Prudential PMS",
style: TextStyle(
fontSize: tSize14, fontWeight: FontWeight.w500, color: skyBlue),
),
SizedBox(
height: 12,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"\u{20B9} 50,00,000",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: blackColor),
),
SizedBox(
height: 5,
),
Text(
"ICICI Prudential PMS",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: greyColor),
),
SizedBox(
height: 14,
),
Text(
"\u{20B9} 2,02,993 (+4.06%)",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: green2Color),
),
SizedBox(
height: 5,
),
Text(
"Gains & Loss",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: greyColor),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"\u{20B9} 52,02,993",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: blackColor),
),
SizedBox(
height: 5,
),
Text(
"Current Market Value",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: greyColor),
),
SizedBox(
height: 14,
),
Text(
"\u{20B9} 5",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: blackColor),
),
SizedBox(
height: 5,
),
Text(
"Total Holdings",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: greyColor),
),
],
),
SizedBox(
width: 0,
)
],
),
],),
),
AnimatedContainer(
duration: Duration(milliseconds: 300),
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
),
// padding: EdgeInsets.only(left: 15, right: 15),
child: Column(
children: [
_isExpanded
? SizedBox.shrink()
: FutureBuilder(
future: _showList1(),
/// will wait untill box animation completed
builder: (context, snapshot) {
if (!snapshot.hasData) {
return SizedBox();
}
return Center(
child: Padding(
padding: const EdgeInsets.only(
top: 20.0, bottom: 00, left: 70, right: 70),
child: SizedBox(
height: 25,
width: 100,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: skyBlue,
shadowColor: Colors.transparent),
onPressed: () {
setState(() {
isOnPMS = !isOnPMS;
if (!_isExpanded) {
setState(() {
_height = 350;
_isExpanded = true;
});
} else {
setState(() {
_height = 50;
_isExpanded = false;
});
}
});
print(_isExpanded);
},
child: Text("View More"),
),
),
),
);
}),
_isExpanded
? FutureBuilder(
future: _showList(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return SizedBox();
}
return Padding(
padding: const EdgeInsets.only(
top: 20.0, bottom: 00, left: 0, right: 0),
child: Column(
children: [
DataTable(
columns: const <DataColumn>[
DataColumn(
label: Text(
'#',style: TextStyle(color: Colors.white),
),
),
DataColumn(
label: Text(
'STOCK',style: TextStyle(color: Colors.white),
),
),
DataColumn(
label: Text(
'SECTOR',style: TextStyle(color: Colors.white),
),
),
DataColumn(
label: Text(
'WEIGHT',style: TextStyle(color: Colors.white),
),
),
],
rows: const <DataRow>[
DataRow(
cells: <DataCell>[
DataCell(Text('1')),
DataCell(Text('TCS')),
DataCell(Text('Global')),
DataCell(Text('11%')),
],
),
DataRow(
cells: <DataCell>[
DataCell(Text('2')),
DataCell(Text('DMART')),
DataCell(Text('Consumers')),
DataCell(Text('10%')),
],
),
DataRow(
cells: <DataCell>[
DataCell(Text('3')),
DataCell(Text('ICICIBANK')),
DataCell(Text('Financials')),
DataCell(Text('12%')),
],
),
DataRow(
cells: <DataCell>[
DataCell(Text('4')),
DataCell(Text('RELIANCE')),
DataCell(Text('Industrial')),
DataCell(Text('13%')),
],
),
],
dividerThickness: 0,
headingRowColor:
MaterialStateColor.resolveWith(
(states) => greyColor),
headingRowHeight: 30,
),
Center(
child: Padding(
padding: const EdgeInsets.only(
top: 20.0,
bottom: 00,
left: 70,
right: 70),
child: SizedBox(
height: 25,
width: 100,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: skyBlue,
shadowColor: Colors.transparent),
onPressed: () {
setState(() {
isOnPMS = !isOnPMS;
if (!_isExpanded) {
setState(() {
_height = 350;
_isExpanded = true;
});
} else {
setState(() {
_height = 50;
_isExpanded = false;
});
}
});
print(_isExpanded);
},
child: const Text('View Less'),
),
),
),
)
],
),
);
})
: SizedBox.shrink(),
],
),
)
],
),
);
}
}
I want like this dataDable.
this is my ui which I created.
Wrap DataTable with SingleChildScrollView and set scrollDirection to horizontal.
Use TableBorder to remove divider.

How to have custom color and border if selected

I wanted to implement a theme picker in my app so I made a dialog and got the title of the theme and the index with which it's going to be chosen class... now I want the dialog to show a border around the selected theme and show the background color of each theme
this is the code I use for the class:
class MultiThemeModel {
int index;
String themeName;
MultiThemeModel({required this.index, required this.themeName});
}
titlesForThemeModel(int index) {
switch (index) {
case 0:
return 'Luxury Purple';
case 1:
return 'Red Wine';
}
return 'No theme for index';
}
List<MultiThemeModel> get themes => List<MultiThemeModel>.generate(
2,
(index) =>
MultiThemeModel(index: index, themeName: titlesForThemeModel(index)));
List<Widget> get widgets => themes
.map((themeData) => MultipleThemeViewerWidget(themeData: themeData))
.toList();
what do I need to do to implement the features described above? I thought about maybe having a boolean and a color property in the class but I don't know how to map it and get it into the list... would be great to get some advice
thanks for the help in advance:)
Edit:
this is the Container for the colors:
class MultipleThemeViewerWidget extends StatelessWidget {
MultipleThemeViewerWidget({Key? key, required this.themeData})
: super(key: key);
final MultiThemeModel themeData;
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
getThemeManager(context).selectThemeAtIndex(themeData.index);
},
child: Container(
height: 60,
width: 105,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Theme.of(context).scaffoldBackgroundColor.withOpacity(.3),
border: Border.all(
color: Theme.of(context).scaffoldBackgroundColor, width: 3)),
child: Center(
child: Text(
themeData.themeName,
style: GoogleFonts.poppins(
textStyle: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Theme.of(context).scaffoldBackgroundColor,
),
),
),
),
),
);
}
}
this is the dialog I have for the implementation:
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
),
elevation: 1,
backgroundColor: Theme.of(context).indicatorColor,
insetAnimationCurve: Curves.decelerate,
child: SizedBox(
height: 170,
width: 320,
child: Stack(
children: [
Padding(
padding: const EdgeInsets.only(
top: 25,
left: 35,
right: 35,
),
child: Stack(
children: [
Container(
width: 250,
height: 30,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(90),
color: Colors.black,
),
),
GestureDetector(
onTap: () {
selected = false;
print(selected);
},
child: AnimatedContainer(
duration: const Duration(
milliseconds: 200,
),
width: 138,
height: 30,
decoration: BoxDecoration(
color: Theme.of(context)
.indicatorColor,
borderRadius:
BorderRadius.circular(90),
border: Border.all(
color: Colors.black,
width: 1,
),
),
child: Center(
child: Text(
'Light Mode',
style: GoogleFonts.poppins(
textStyle: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 112,
),
child: GestureDetector(
onTap: () {
setState(() {
selected = true;
print(selected);
});
},
child: AnimatedContainer(
duration: const Duration(
milliseconds: 200,
),
width: 138,
height: 30,
decoration: BoxDecoration(
color: selected
? Colors.black
: Colors.transparent,
borderRadius:
BorderRadius.circular(90),
),
child: Center(
child: Text(
'Dark Mode',
style: GoogleFonts.poppins(
textStyle: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
),
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(
top: 85,
left: 35,
right: 35,
),
child: SizedBox(
height: 60,
width: 250,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: widgets),
),
),
],
),
),
);
getThemeManager:
/// Returns the [ThemeManger] that
ThemeManager getThemeManager(BuildContext context) =>
Provider.of<ThemeManager>(context, listen: false);
class ThemeModel {
final ThemeData? selectedTheme;
final ThemeData? darkTheme;
final ThemeMode? themeMode;
ThemeModel({
required this.selectedTheme,
required this.darkTheme,
required this.themeMode,
});
}

Navigate back from page flutter

I want to navigate to the previous page using the arrow icon I have added in this code. to where I want to add that code and tell me how to code that part. want to navigate from detail_screen.dart to home_page.dart using the arrow icon I have added. can someone please provide a proper answer for this?
detail_screen.dart
import 'package:flutter/material.dart';
class DetailsScreen extends StatelessWidget {
const DetailsScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
//shadowColor: Colors.transparent,
leading: Icon(
Icons.arrow_back_rounded,
color: Colors.black,
),
actions: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: const [
CircleAvatar(
radius: 40,
backgroundColor: Colors.white,
child:
Icon(Icons.favorite_border_outlined, color: Colors.black),
),
CircleAvatar(
radius: 40,
backgroundColor: Colors.white,
child: Icon(Icons.shopping_bag_outlined, color: Colors.black),
)
],
),
),
],
),
body: Column(
children: <Widget>[
Stack(
alignment: Alignment.bottomRight,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 0),
child: Container(
height: MediaQuery.of(context).size.height * 0.9,
width: MediaQuery.of(context).size.width * 0.9,
padding: const EdgeInsets.only(left: 20),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/image23.png"),
fit: BoxFit.contain,
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20,
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.grey.shade100,
),
alignment: const Alignment(1, 1),
height: 310,
width: 375,
child: Column(
children: [
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
"Crop Top",
style: TextStyle(
fontSize: 24,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: 25,
height: 25,
child: FloatingActionButton(
onPressed: () {},
backgroundColor: Colors.blueAccent,
child: null),
),
),
SizedBox(
width: 25,
height: 25,
child: FloatingActionButton(
onPressed: () {},
backgroundColor: Colors.amber,
child: null),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: SizedBox(
width: 25,
height: 25,
child: FloatingActionButton(
onPressed: () {},
backgroundColor: Colors.lightGreen,
child: null),
),
),
]),
],
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 270, 10),
child: Text(
"Sizes",
style: TextStyle(
fontSize: 16,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
// SizedBox(
// height: 30,
// ),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black,
),
),
onPressed: () {
print('XS');
},
child: Text('XS'),
),
TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black,
),
),
onPressed: () {
print('X');
},
child: Text('S'),
),
TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black,
),
),
onPressed: () {
print('M');
},
child: Text('M'),
),
TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black,
),
),
onPressed: () {
print('L');
},
child: Text('L'),
),
TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black,
),
),
onPressed: () {
print('XL');
},
child: Text('XL'),
),
],
),
SizedBox(
height: 30,
),
Row(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"30% off",
style: TextStyle(
fontSize: 25,
color: Colors.purple,
fontWeight: FontWeight.w700),
),
),
],
),
SizedBox(
height: 30,
),
Row(
children: const [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Rs.2950",
style: TextStyle(
fontSize: 18,
color: Color(0xff8399A9),
fontWeight: FontWeight.w700,
decoration: TextDecoration.lineThrough),
),
),
Text(
"Rs.2750",
style: TextStyle(
fontSize: 24,
color: Color(0xff0DA75F),
fontWeight: FontWeight.w700,
),
),
],
),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(230, 110, 0, 0),
child: ElevatedButton(
onPressed: () {},
child: const Text(
"Add to Cart ",
),
style: ElevatedButton.styleFrom(
primary: Colors.pinkAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
bottomRight: Radius.circular(20),
),
),
padding: const EdgeInsets.all(28),
),
),
),
],
),
],
),
);
}
}
home_page.dart
import 'package:flutter/material.dart';
import 'package:fashion_app/details_screen.dart';
import 'package:flutter/services.dart';
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
//final double _borderRadious = 24;
#override
#override
void initState() {
// TODO: implement initState
super.initState();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.pinkAccent,
),
body: ListView(
padding: const EdgeInsets.only(top: 40, left: 20, right: 20),
children: [
HelloText(),
Name(),
SizedBox(
height: 10,
),
buildSearchInput(),
SizedBox(
height: 10,
),
Stack(children: [
Padding(
padding: const EdgeInsets.fromLTRB(10, 45, 10, 0),
child: TextButton(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.red.shade50,
),
height: 137,
width: 327,
child: Column(
children: const [
Padding(
padding: const EdgeInsets.fromLTRB(20, 40, 100, 40),
child: Text(
"Summer Collections",
style: TextStyle(
fontSize: 24,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.justify,
),
),
],
)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DetailsScreen()));
},
),
),
const Padding(
padding: EdgeInsets.fromLTRB(200, 0, 10, 0),
child: Image(
image: AssetImage("assets/images/dressone.png"),
),
),
]),
Stack(children: [
Padding(
padding: const EdgeInsets.fromLTRB(10, 45, 10, 0),
child: TextButton(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.red.shade50,
),
height: 137,
width: 327,
child: Column(
children: const [
Padding(
padding: const EdgeInsets.fromLTRB(20, 40, 100, 40),
child: Text(
"Winter Collections",
style: TextStyle(
fontSize: 24,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.justify,
),
),
],
)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DetailsScreen()));
},
),
),
const Padding(
padding: EdgeInsets.fromLTRB(200, 0, 10, 0),
child: Image(
image: AssetImage("assets/images/dresstwo.png"),
),
),
]),
Stack(children: [
Padding(
padding: const EdgeInsets.fromLTRB(5, 20, 10, 0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.blue.shade50,
),
height: 137,
width: 327,
child: Row(
children: const [
Padding(
padding: EdgeInsets.fromLTRB(150, 40, 0, 40),
child: Text(
"Get",
style: TextStyle(
fontSize: 24,
color: Colors.black,
fontWeight: FontWeight.w700),
),
),
Padding(
padding: EdgeInsets.all(5.0),
child: Text(
"30%",
style: TextStyle(
fontSize: 24,
color: Colors.purple,
fontWeight: FontWeight.w700),
),
),
Text(
"Off",
style: TextStyle(
fontSize: 24,
color: Colors.black,
fontWeight: FontWeight.w700),
),
],
)),
),
const Padding(
padding: EdgeInsets.fromLTRB(15, 0, 10, 0),
child: Image(
image: AssetImage("assets/images/dressthree.png"),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(230, 110, 0, 40),
child: ElevatedButton(
onPressed: () {},
child: const Text(
"Know More",
),
style: ElevatedButton.styleFrom(
primary: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
bottomRight: Radius.circular(20))),
padding: const EdgeInsets.all(15)),
),
),
]),
],
),
);
}
Widget HelloText() => Container(
child: Row(children: [
Text(
'Hello,',
style: TextStyle(
fontSize: 28,
color: Colors.black,
fontWeight: FontWeight.w500,
),
),
]),
);
Widget Name() => Container(
child: Row(children: [
Text(
'Nirasha',
style: TextStyle(
fontSize: 28,
color: Colors.amber,
fontWeight: FontWeight.w500,
),
),
]),
);
Widget buildSearchInput() => Container(
decoration: BoxDecoration(
color: Colors.grey[300], borderRadius: BorderRadius.circular(20)),
child: Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20),
child: Row(
children: [
Icon(
Icons.search,
size: 30,
color: Colors.grey,
),
Flexible(
child: TextField(
decoration: InputDecoration(border: InputBorder.none),
),
),
],
),
),
);
}
use following Structure in detail_screen.dart scaffold:
body : SafeArea(
child: Column(
children: <Widget>[
Container(child: IconButton(
icon: Icon(
Icons.chevron_left_sharp, //backIcon
color: Colors.indigo,
size: 30,
),
onPressed: () {
Navigator.pop(context);
},
),
-------------------- //other Elements Of body
]
),
)
Please use this : Navigator.of(context).pop();
In your detail_screen.dart, use this code in Appbar leading.
IconButton(
icon: new Icon(
Icons.arrow_back_rounded,
color: Colors.black,
),
onPressed: () => Navigator.pop(context),
),
Used this code now it is working.
leading: IconButton(
icon: new Icon(
Icons.arrow_back_rounded,
color: Colors.black,
),
onPressed: () {Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage()));
},
),
In your DetailScreen, your leading widget should be IconButton and handle onpressed event of that IconButton to pop the activity from stack.
Here it is:
leading: IconButton(
icon: new Icon(
Icons.arrow_back_rounded,
color: Colors.black,
),
onPressed: () => Navigator.pop(context),
),