dart

Flutter 模仿微信读书实现案例

时光毁灭记忆、已成空白 提交于 2020-11-28 08:38:06
前言: 各位同学大家好,有一段时间没有给大家更新博客了,最近使用flutter跨平台写了一个模仿微信读书app demo版本(模仿其中部分经典页面不是全部)觉得有几个点值得分享一下,趁着今天放假,就发文章分线给大家,那么废话不多说我们正式开始 效果图: Screenrecorder-2020-09-12-13-41-20-726[00_00_00--00_00_20].gif 准备工作: 需要安装flutter的开发环境:大家可以去看看之前的教程: 1 win系统flutter开发环境安装教程: https://www.jianshu.com/p/152447bc8718 2 mac系统flutter开发环境安装教程: https://www.jianshu.com/p/bad2c35b41e3 具体实现: QQ截图20200912135506.png 效果分析: 我们看到底部的tab和上面的卡片形成了联动我们点击下面的button 和滑动都可以联动,flutter中底部的tab切换我们都是用 bottomNavigationBar 组件来实现,但是要实现联动我们需要配合PageView 来实现: 我们看下 TabNavigator中的代码实现 import 'package:flutter/material.dart'; import 'content_pager.dart';

Flutter开发基础——Dart语法

核能气质少年 提交于 2020-11-28 04:17:26
本文主要介绍Dart开发常用的一些语法 基础语法 Final,Const定义常量 Const 变量在编译时就已经固定。 Final 变量或类变量在第一次使用时被初始化,懒加载。 Const不能定义对象 Final能定义对象 例: //可以省略String这个类型声明 final str = "hi world"; //final String str = "hi world"; const str1 = "hi world"; //const String str1 = "hi world"; 定义多行字符串 String str =""" 保留换行的字符串 可以在编译器里换行 """; String str2 =''' 保留换行的字符串 可以在编译器里换行 '''; print(str); print(str2); double类型初始化时可以赋值为int型 double num1 = 1.0; double num2= 1; print(num1.runtimeType); print("----"); print(num2.runtimeType); Map类型取值map[“key”] 赋值同理 Map testMap = {}; testMap["flag"] = true; print(testMap["flag"]); 在List类型中使用if语句 var

How to call a named constructor from a generic function in Dart/Flutter

☆樱花仙子☆ 提交于 2020-11-27 04:57:37
问题 I want to be able to construct an object from inside a generic function. I tried the following: abstract class Interface { Interface.func(int x); } class Test implements Interface { Test.func(int x){} } T make<T extends Interface>(int x) { // the next line doesn't work return T.func(x); } However, this doesn't work. And I get the following error message: The method 'func' isn't defined for the class 'Type' . Note : I cannot use mirrors because I'm using dart with flutter. 回答1: Dart does not

How to get widget's absolute coordinates on a screen in Flutter?

∥☆過路亽.° 提交于 2020-11-27 04:57:16
问题 How to get widget's absolute coordinates on a screen in Flutter? Or its offset in a parent Example: import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Simple app', theme: ThemeData( primarySwatch: Colors.blue, ), home: SimpleScreen( title: 'Simple screen', ), ); } } class SimpleScreen extends StatefulWidget { final String title; SimpleScreen({Key key, this

How to get widget's absolute coordinates on a screen in Flutter?

℡╲_俬逩灬. 提交于 2020-11-27 04:57:13
问题 How to get widget's absolute coordinates on a screen in Flutter? Or its offset in a parent Example: import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Simple app', theme: ThemeData( primarySwatch: Colors.blue, ), home: SimpleScreen( title: 'Simple screen', ), ); } } class SimpleScreen extends StatefulWidget { final String title; SimpleScreen({Key key, this

Flutter AbsorbPointer vs IgnorePointer difference

≯℡__Kan透↙ 提交于 2020-11-26 07:06:52
问题 What is the difference between AbsorbPointer and IgnorePointer in flutter? Docs mention: AbsorbPointer prevents its subtree from receiving pointer events by terminating hit testing at itself. IgnorePointer, which also prevents its children from receiving pointer events but is itself invisible to hit testing. I didn't get what is the real life difference between the two. 回答1: The difference is when we have two widgets overlapping each other, that can both receive clicks. Consider a red and

Flutter AbsorbPointer vs IgnorePointer difference

☆樱花仙子☆ 提交于 2020-11-26 07:04:40
问题 What is the difference between AbsorbPointer and IgnorePointer in flutter? Docs mention: AbsorbPointer prevents its subtree from receiving pointer events by terminating hit testing at itself. IgnorePointer, which also prevents its children from receiving pointer events but is itself invisible to hit testing. I didn't get what is the real life difference between the two. 回答1: The difference is when we have two widgets overlapping each other, that can both receive clicks. Consider a red and

Flutter AbsorbPointer vs IgnorePointer difference

只愿长相守 提交于 2020-11-26 07:03:28
问题 What is the difference between AbsorbPointer and IgnorePointer in flutter? Docs mention: AbsorbPointer prevents its subtree from receiving pointer events by terminating hit testing at itself. IgnorePointer, which also prevents its children from receiving pointer events but is itself invisible to hit testing. I didn't get what is the real life difference between the two. 回答1: The difference is when we have two widgets overlapping each other, that can both receive clicks. Consider a red and

【Flutter 1-8】Flutter教程Dart语言——控制语句

十年热恋 提交于 2020-11-25 18:48:43
作者 | 弗拉德 来源 | 弗拉德(公众号:fulade_me) 控制语句 Dart语言的控制语句跟其他常见语言的控制语句是一样的,基本如下: if 和 else for 循环 while 和 do-while 循环 break 和 continue switch 和 case assert 文章首发地址 If 和 Else Dart 支持 if - else 语句,其中 else 是可选的,比如下面的例子。 int i = 0; if (i == 0) { print("value 0"); } else if (i == 1) { print("value 1"); } else { print("other value"); } 如果要遍历的对象实现了 Iterable 接口,则可以使用 forEach() 方法,如果不需要使用到索引,则使用 forEach 方法是一个非常好的选择: Iterable 接口实现了很多方法,比如说 forEach()、any()、where() 等,这些方法可以大大精简我们的代码,减少代码量。 var callbacks = []; for (var i = 0; i < 2; i++) { callbacks.add(() => print(i)); } callbacks.forEach((c) => c()); 像 List 和 Set

Flutter必备开源项目

瘦欲@ 提交于 2020-11-25 11:57:57
首页 动态的展示导航栏的显示和隐藏 日历模块 展示日历的记录, 每日记录生成图片和保存图片 发现 类似朋友圈的内容展示, 图片浏览和保存图片 动态详情模块, 动态的评论和删除评论 多语言国际化 部分页面适配了韩语和英语 颜色主题和暗黑模式 部分页面支持手动的修改项目主题色, 黑色主题(暗黑模式)适配 用到的插件 dio https://pub.dartlang.org/packages/dio Dart社区提供的http请求库,不仅支持常见的网络请求,还支持Restful API、FormData、拦截器、请求取消、Cookie管理、文件上传/下载、超时等操作 provider https://pub.dev/packages/provider Flutter 官方推荐的状态管理插件, 简单的应用状态管理 flutter_redux https://pub.dev/packages/flutter_redux flutter 版的 redux pull_to_refresh https://pub.dev/packages/pull_to_refresh 一个提供上拉加载和下拉刷新的组件,同时支持 Android 和 ios flutter_staggered_grid_view https://pub.dev/packages/flutter_staggered_grid