Thursday, May 17, 2018

Motiv. quote app: PageView for swipe gesture | Infinite PageView in Flut...



If you are fallow along with my Flutter and Dart tutorial series, Yes, that is the only file we have to change(main.dart):
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],
),
);
}
}
view raw main.dart hosted with ❤ by GitHub


Below is a simple example for you to understand basics of PageView.

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