Por favor, alguém me diz porque os botões que deveriam passar as telas não estão funcionado direito. Testei em um emulador android e em um celular android e nada de passar corretamente a view.
import 'package:flutter/material.dart';
import 'PageViewController.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter PageView Demonstratio',
theme: ThemeData(
primarySwatch: Colors.green,
),
home: HomeWidget(),
);
}
}
class HomeWidget extends StatefulWidget {
@override
_HomeWidgetState createState() => _HomeWidgetState();
}
class _HomeWidgetState extends State<HomeWidget> {
PageController controller;
@override
void initState() {
super.initState();
controller = PageController(initialPage: 0);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
List<String> pages = ["BATATA", "CENOURA", "MAGERICÃO"];
return Scaffold(
appBar: AppBar(
actions: <Widget>[
IconButton(
icon: Icon(Icons.keyboard_arrow_left),
onPressed: () {
controller.previousPage(
curve: Curves.easeInOutBack,
duration: Duration(milliseconds: 300));
},
),
IconButton(
icon: Icon(Icons.home),
onPressed: () {
controller.jumpToPage(0);
},
),
IconButton(
icon: Icon(Icons.keyboard_arrow_right),
onPressed: () {
controller.nextPage(
curve: Curves.easeInOutBack,
duration: Duration(milliseconds: 300));
},
),
],
title: Text("Page View"),
),
body: PageView.builder(
controller: controller,
itemCount: pages.length,
itemBuilder: (BuildContext context, int index) {
print(index);
return Center(child: Text(pages[index]));
},
));
}
}