Giter Site home page Giter Site logo

flutter_boss's Introduction

flutter仿BOSS直聘(二),大前端技术实现

项目简介

记得上一篇的写作时间还在2018年2月份,已经很久没更新了,而flutter的版本更新了好几次,自flutter 1.0正式版推出之后,一直有打算把之前的项目重写一下,因为flutter本身更新了许多新特性,老的已经是过去式了,也老有人来问我,之前的项目运行不了,是的,因为sdk太老了,而且之前的项目纯粹是练手玩。

在过去的这段时间里,踊跃出了很多关于flutter的技术文章和开源项目例子,基本上每天都有,同比RN刚出来时,热情度远超RN。于是,笔者怀着对新技术热情的学习态度重写了这个开源项目,并且后续也会不断完善。

为什么选仿BOSS直聘作为题材? 因为这款APP相信大家都在使用,里面组件繁多且有一定复杂度,能衍生出来许多基于flutter组件库的子项目,里面有些功能,比如地图,IM,后面都会使用flutter来实现。为了让项目更接近真实,这次连服务端也实现了。先把开源地址提供给大家:

github地址:

服务端版本:flutter仿boss直聘服务端.

flutter版本:flutter仿boss直聘.

项目效果图:

img

相关技术点

服务端:

  • 基于puppeteer + mongo + nodejs实现爬虫服务器,使用nuxt + koa2 + vue实现服务端渲染以及api服务接口。这里就不过多占用篇幅了,本文主要还是讲flutter,对前端感兴趣的会另外分享相关技术话题。

flutter端:

  • 项目中使用以下组件,请记住一句咒语:flutter一切皆组件。 Container, Row, Column, Flex, ListView, CustomListView, Wrap, Padding, Center, Future, FutureBuilder, Expanded, Navigator, BottomNavigationBar, GesureDetector, Listener, CircleAvatar等以及一些自定义组件。
  • 布局语义化,不滥用布局组件,并尽量简化组件嵌套结构

技术细节

  • 实现启动画面,在启动1.5秒后,跳转到app里,并且把启动画面的路由remove掉。
Navigator.of(context).pushAndRemoveUntil(
    PageRouteBuilder<Null>(
      pageBuilder: (BuildContext context, Animation<double> animation,
          Animation<double> secondaryAnimation) {
        return AnimatedBuilder(
          animation: animation,
          builder: (BuildContext context, Widget child) {
            return Opacity(
              opacity: animation.value,
              child: new MainPage(title: 'Boss直聘'),
            );
          },
        );
      },
      transitionDuration: Duration(milliseconds: 300),
    ),
    (Route route) => route == null);
  • 列表页面,没啥好说的,ListView大家应该都用过,只是需要记住一点,列表再跳转详情时需要记录当前列表的滚动位置,只需加入以下代码即可: key: new PageStorageKey('key-name')

  • Hero动画,在详情页面里,用了2处Hero动画,Hero动画是在route切换过程中执行的动画。需要当前页和目标页一一对应起来。

Hero(
  tag: heroLogo,
  child: ClipRRect(
    borderRadius: new BorderRadius.circular(8.0),
    child: Image.network(
      widget.company.logo,
      width: 70,
      height: 70,
    ),
  ),
)),
  • CustomListView滑动时appBar显示隐藏title。大家都知道,flexibleSpace里的CollapseMode.parallax属性可以在屏幕滚动时把title移动到appBar里,可实际上,布局是定制的,实现不了官方的那种效果,于是通过监听ScrollController并计算滚动位置的方式修改state属性让appBar的title根据滚动位置显示隐藏。
 _scrollListener() {
    setState(() {
      if (_scrollController.offset < 56 && _isShow) {
        _isShow = false;
      } else if (_scrollController.offset >= 56 && _isShow == false) {
        _isShow = true;
      }
    });
  }

TODO-LIST

  • 公司详情页slidePanel控件实现
  • 公共弹层组件封装
  • 消息列表控件封装并实现测滑删除功能

qq技术Flutter讨论千人群号:468010872

img

联系方式

微信:heruijun2258,注明来意。

flutter_boss's People

Contributors

daiwj avatar hrj8848 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter_boss's Issues

Json parsing failure in message.dart company.dart job.dart List<dynamic > cannot to List<message >

When I git clone this project , I find that it cause a RuntimeException , and message company job Page is Empty !
I find that I change method fromJson(String json)
from :
static List fromJson(String json) {
return JSON
.decode(json)['list']
.map((obj) => Job.fromMap(obj))
.toList();
}

to:
static List fromJson(String json) {
List _jobs = [];
for (var value in new JsonDecoder().convert(json)['list']) {
_jobs.add(Job.fromMap(value));
}
return _jobs;
}

and make method buildJobItem return Widget , The Project work well .

代码克隆下来无法运行

IDE :Android studio 4.1.1
启动时报如下错误:

event sent after app closed: {id: 0, progressId: null, message: Running "flutter pub get" in flutter_bottomnav...}
event sent after app closed: {id: 0, progressId: null, finished: true}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It's being deprecated in favor of Android embedding v2. Follow the
steps at

https://flutter.dev/go/android-project-migration

to migrate your project.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Launching lib/main.dart on Mi 10 Pro in debug mode...
[!] Your app isn't using AndroidX.
To avoid potential build failures, you can quickly migrate your app by following the steps on https://goo.gl/CP92wY .
Running Gradle task 'assembleDebug'...
/Users/zhuzhiqiang/gradle-4.5.1/.gradle/caches/transforms-1/files-1.1/core-1.1.0.aar/99875dad3578891d7a573f3ed4990bf2/res/values/values.xml:7:5-70: AAPT: error: resource android:attr/fontVariationSettings not found.

/Users/zhuzhiqiang/gradle-4.5.1/.gradle/caches/transforms-1/files-1.1/core-1.1.0.aar/99875dad3578891d7a573f3ed4990bf2/res/values/values.xml:7:5-70: AAPT: error: resource android:attr/ttcIndex not found.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:processDebugResources'.

Failed to process resources, see aapt output above for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 13s
Exception: Gradle task assembleDebug failed with exit code 1

跟着上面的提示修改了一下
在 pubspec.yaml 添加了
module:
androidX: true

并在android/gradle.properties里面添加了
android.useAndroidX=true
android.enableJetifier=true

然后执行flutter clean

还是无法启动

event sent after app closed: {id: 0, progressId: null, message: Running "flutter pub get" in flutter_bottomnav...}
event sent after app closed: {id: 0, progressId: null, finished: true}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It's being deprecated in favor of Android embedding v2. Follow the
steps at

https://flutter.dev/go/android-project-migration

to migrate your project.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Launching lib/main.dart on Mi 10 Pro in debug mode...
Running Gradle task 'assembleDebug'...

启动抛错

[ +24 ms] [DEVICE LOG] Filtering the log data using "processImagePath CONTAINS "554BF24E-90D0-4205-A282-92BF7360C615""
[ +8 ms] [DEVICE LOG] Timestamp (process)[PID]
[+2207 ms] compiler message: lib/app/view/message_view.dart:46:20: Error: Method not found: 'MessageListItem'.
[ ] compiler message: child: new MessageListItem(message)
[ ] compiler message: ^^^^^^^^^^^^^^^
[ +3 ms] compiler message: lib/app/view/message_view.dart:46:35: Error: Too many positional arguments: 0 allowed, but 1 found.
[ ] compiler message: Try removing the extra positional arguments.
[ ] compiler message: child: new MessageListItem(message)
[ ] compiler message: ^^^^^^^^^
[ +427 ms] compiler message: lib/app/model/company.dart:30:12: Error: Getter not found: 'JSON'.
[ ] compiler message: return JSON
[ ] compiler message: ^^^^
[ +1 ms] compiler message: lib/app/model/job.dart:23:12: Error: Getter not found: 'JSON'.
[ ] compiler message: return JSON
[ ] compiler message: ^^^^
[ ] compiler message: lib/app/model/message.dart:21:12: Error: Getter not found: 'JSON'.
[ ] compiler message: return JSON
[ ] compiler message: ^^^^
[ +547 ms] Compiler failed on /Volumes/D/code/Flutter/ios_apps/flutter_boss/lib/main.dart
[ ] Error launching application on iPhone 8 Plus.
[ +9 ms] "flutter run" took 6,234ms.

#0 throwToolExit (package:flutter_tools/src/base/common.dart:26:3)
#1 RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:417:7)

#2 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:356:18)
#3 _asyncThenWrapperHelper. (dart:async/runtime/libasync_patch.dart:77:64)
#4 _rootRunUnary (dart:async/zone.dart:1132:38)
#5 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#6 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#7 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#8 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#9 Future._complete (dart:async/future_impl.dart:476:7)
#10 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#11 _AsyncAwaitCompleter.complete (dart:async/runtime/libasync_patch.dart:28:18)
#12 _completeOnAsyncReturn (dart:async/runtime/libasync_patch.dart:295:13)
#13 RunCommand.usageValues (package:flutter_tools/src/commands/run.dart)
#14 _asyncThenWrapperHelper. (dart:async/runtime/libasync_patch.dart:77:64)
#15 _rootRunUnary (dart:async/zone.dart:1132:38)
#16 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#17 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#18 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#19 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#20 Future._complete (dart:async/future_impl.dart:476:7)
#21 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#22 _AsyncAwaitCompleter.complete. (dart:async/runtime/libasync_patch.dart:33:20)
#23 _rootRun (dart:async/zone.dart:1124:13)
#24 _CustomZone.run (dart:async/zone.dart:1021:19)
#25 _CustomZone.bindCallback. (dart:async/zone.dart:947:23)
#26 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#27 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#28 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#29 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)

======================
PS:刚刚好入坑~~

关于tab切换页面重新加载的问题

您好,看到代码中:

 body: new TabBarView(
        children: <Widget>[
          new JobsTab(), new CompanyTab(), new MessageTab(), new MineTab()],
        controller: _controller,
      ),

tabbarview的这种写法,每次切换的时候,这几个页面都会重新加载,请问有什么好的处理方式吗?

Error: No pubspec.yaml file found. 缺少配置文件

mac:react-native-lagou-master pro$ flutter run
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Do not run this command from the root of your git clone of Flutter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.