I am a newbie at Flutter. I am making a website for publishing. I am trying to jumpto my page using SingleChildScrollView’s controller. I have a custom app bar. And The custom app bar has 4 buttons. But the problem is: The custom app bar is in different page. My purpose is: When I click the this buttons. My SingleChildScrollView jumps to the point. I can not move it without using same page. But I want to use it at different page.
Here is my code: ( Custom app bar page )
import 'package:flutter/material.dart';
class TopBarContents extends StatefulWidget {
TopBarContents();
@override
_TopBarContentsState createState() => _TopBarContentsState();
}
class _TopBarContentsState extends State<TopBarContents> {
final List _isHovering = [
false,
false,
false,
false,
false,
false,
false,
false
];
static int _counter = 0;
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
var screenSize = MediaQuery.of(context).size;
ScrollController scrollController = ScrollController();
void _scroller() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
// final double start = 0;
// final double start = 1350;
final double start = 4050;
scrollController.jumpTo(start);
// scrollController.animateTo(start, duration: Duration(seconds: 1), curve: Curves.easeIn);
});
}
return Container(
color: Colors.white.withOpacity(0.5),
child: Padding(
padding: EdgeInsets.all(20),
child:
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(width: screenSize.width/6,),
Image.asset("images/logo_hesap.png", width: width/10,),
SizedBox(width: screenSize.width / 15),
InkWell(
onHover: (value) {
setState(() {
value
? _isHovering[0] = true
: _isHovering[0] = false;
});
},
onTap: () {
_scroller();
final double start = 4050;
scrollController.jumpTo(start);
},
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Ana Sayfa',
style: TextStyle(
color: _isHovering[0]
? Color(0xff000000)
: Color(0xff32b146),
fontWeight: FontWeight.bold,
fontSize: 16
),
),
The main page: ( The page has only scrollview and other widgets)
SingleChildScrollView(
controller: scrollController,)
2
Answers
Pass values between the two pages by calling the class of the first page in the class of the second page, and the value parameter to be passed must be required. Then, in the class in the second class, create a value equal to the value to be passed, and then you can use it in your button.
I will try to explain simple to complex.
MySingletonClass.scrollController