If you are fallow along with my Flutter and Dart tutorial series, Yes, that is the only file we have to change(main.dart):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:motivational_quote_app/disney_page.dart'; | |
import 'package:motivational_quote_app/home_page.dart'; | |
import 'package:motivational_quote_app/lennon_page.dart'; | |
void main() => runApp(new QuoteApp()); | |
class QuoteApp extends StatelessWidget { | |
List<Widget> pages = [HomePage(), DisneyPage(), LennonPage()]; | |
@override | |
Widget build(BuildContext context) { | |
return new MaterialApp( | |
title: 'Motivational Quote App', | |
home: PageView.builder( | |
itemCount: pages.length, | |
itemBuilder: (BuildContext context, int index) => pages[index], | |
), | |
); | |
} | |
} |
Below is a simple example for you to understand basics of PageView.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(LimeApp()); | |
class LimeApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Lime', | |
theme: ThemeData( | |
canvasColor: Colors.primaries[6], | |
), | |
home: MainPage(), | |
); | |
} | |
} | |
class MainPage extends StatelessWidget { | |
List<Widget> pages = [YourPage(), YourSecondPage(), YourThirdPage()]; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Container( | |
decoration: BoxDecoration( | |
color: Colors.black54, | |
), | |
margin: EdgeInsets.symmetric( | |
vertical: 50.0, | |
horizontal: 10.0, | |
), | |
child: PageView.builder( | |
controller: PageController( | |
initialPage: 1, | |
viewportFraction: 0.8, | |
), | |
itemBuilder: (_, int index) => pages[index]; | |
), | |
), | |
); | |
} | |
} |
Output for the above code should look like below screencast:
No comments:
Post a Comment