From d7280443928749a1f3cc76db95b0a59a97e7adfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E6=9D=83?= Date: Tue, 23 Jul 2019 23:04:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:sparkles:=20=E6=96=B0=E5=A2=9Eview?= =?UTF-8?q?=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/demo/view_demo.dart | 44 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/demo/view_demo.dart b/lib/demo/view_demo.dart index 73981a8..d4e12dd 100644 --- a/lib/demo/view_demo.dart +++ b/lib/demo/view_demo.dart @@ -1 +1,43 @@ -import 'package:flutter/material.dart'; \ No newline at end of file +import 'package:flutter/material.dart'; + +class ViewDemo extends StatelessWidget { + @override + Widget build(BuildContext context) { + // TODO: implement build + return PageView( + // pageSnapping: false, //设置滑动不自动跳转页面 + reverse: true, // 反转 最后一页第一展示 + scrollDirection: Axis.vertical, // 垂直翻页 默认水平 + onPageChanged: (currPage) => debugPrint('page: $currPage'), //页面调转的回调 + controller: PageController( + initialPage: 1, + ), + children: [ + Container( + color: Colors.brown[900], + alignment: Alignment(0.0, 0.0), + child: Text( + 'ONE', + style: TextStyle(fontSize: 32.0, color: Colors.white) + ), + ), + Container( + color: Colors.grey[900], + alignment: Alignment(0.0, 0.0), + child: Text( + 'TWO', + style: TextStyle(fontSize: 32.0, color: Colors.white) + ), + ), + Container( + color: Colors.blueGrey[900], + alignment: Alignment(0.0, 0.0), + child: Text( + 'THREE', + style: TextStyle(fontSize: 32.0, color: Colors.white) + ), + ) + ], + ); + } +} \ No newline at end of file From 0c52702969290f726c428102212909a3b0e7f1fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E6=9D=83?= Date: Wed, 24 Jul 2019 22:08:44 +0800 Subject: [PATCH 2/2] :art: learning view --- lib/demo/view_demo.dart | 65 ++++++++++++++++++++++++++++++++++ lib/model/post.dart | 78 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 134 insertions(+), 9 deletions(-) diff --git a/lib/demo/view_demo.dart b/lib/demo/view_demo.dart index d4e12dd..f4f585a 100644 --- a/lib/demo/view_demo.dart +++ b/lib/demo/view_demo.dart @@ -1,6 +1,71 @@ import 'package:flutter/material.dart'; +import '../model/post.dart'; class ViewDemo extends StatelessWidget { + + @override + Widget build(BuildContext context) { + // TODO: implement build + return GridViewBuildDemo(); + } +} + + +class GridViewBuildDemo extends StatelessWidget { + Widget _itemsBulder(BuildContext context, int index) { + return Container( + child: Image.network( + posts[index].imageUrl, + fit: BoxFit.cover + ), + ); + } + + @override + Widget build(BuildContext context) { + // TODO: implement build + return GridView.builder( + itemCount: posts.length, + itemBuilder: _itemsBulder, + padding: EdgeInsets.all(8.0), + gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent( + maxCrossAxisExtent: 200.0, + crossAxisSpacing: 16.0, + mainAxisSpacing: 16.0 + ), + ); + } +} + + +// GridViewBuild视图 +class GridViewCountDemo extends StatelessWidget { + List _buildTiles(int length) { + return List.generate(length, (int index) { + return Container( + color: Colors.grey[300], + alignment: Alignment(0.0, 0.0), + child: Text( + 'Ttem $index', + style: TextStyle(fontSize: 18.0, color: Colors.grey) + ), + ); + }); + } + @override + Widget build(BuildContext context) { + // TODO: implement build + return GridView.count( // 网格视图 + crossAxisCount: 3, + crossAxisSpacing: 16.0, + mainAxisSpacing: 16.0, + children: _buildTiles(100) + ); + } + + +} +class PageViewDemo extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build diff --git a/lib/model/post.dart b/lib/model/post.dart index b8b8f90..0ae7bcc 100644 --- a/lib/model/post.dart +++ b/lib/model/post.dart @@ -12,18 +12,78 @@ class Post { final List posts = [ Post( - title: '嗷嗷嗷', - author: 'kevin', - imageUrl: 'http://126306.sgss8.com/upload/2016042923/232418_1381.jpg' + title: 'Candy Shop', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/candy-shop.jpg', ), Post( - title: '啵啵啵', - author: 'tony', - imageUrl: 'http://img.jrzj.com/uploadfile/2016/0425/20160425034606619.jpg' + title: 'Childhood in a picture', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/childhood-in-a-picture.jpg', ), Post( - title: '擦擦擦', - author: 'duk', - imageUrl: 'https://thumbs.dreamstime.com/z/%E5%BD%93%E7%8C%AA%E9%A3%9E%E8%A1%8C%EF%BC%8C%E9%A3%9E%E8%A1%8C%E7%8C%AA-102257918.jpg' + title: 'Contained', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/contained.jpg', + ), + Post( + title: 'Dragon', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/dragon.jpg', + ), + Post( + title: 'Free Hugs', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/free_hugs.jpg', + ), + Post( + title: 'Gravity Falls', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/gravity-falls.png', + ), + Post( + title: 'Icecream Truck', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/icecreamtruck.png', + ), + Post( + title: 'keyclack', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/keyclack.jpg', + ), + Post( + title: 'Overkill', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/overkill.png', + ), + Post( + title: 'Say Hello to Barry', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/say-hello-to-barry.jpg', + ), + Post( + title: 'Space Skull', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/space-skull.jpg', + ), + Post( + title: 'The Old Fashioned', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/the-old-fashioned.png', + ), + Post( + title: 'Tornado', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/tornado.jpg', + ), + Post( + title: 'Undo', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/undo.jpg', + ), + Post( + title: 'White Dragon', + author: 'Mohamed Chahin', + imageUrl: 'https://resources.ninghao.org/images/white-dragon.jpg', ) ]; \ No newline at end of file