隨診醫(yī)生社區(qū)醫(yī)生版極速開發(fā)直播1.2

創(chuàng)建主界面

由于需要針對基層醫(yī)療機(jī)構(gòu)出診及家庭醫(yī)生需求,需要快速開發(fā)出一個簡單的移動應(yīng)用,決定采用Google在2018年2月新推出的Flutter技術(shù),來開發(fā)這個新的App。
首先主頁的底部像大多數(shù)應(yīng)用一樣,有一個TabBar,共有5個選項:

  • 日程
    記錄醫(yī)生在醫(yī)院出診、預(yù)約計劃和執(zhí)行情況,以及走訪社區(qū)出診計劃和執(zhí)行情況。在醫(yī)院就診需要記錄醫(yī)院、科室和出診時間,外出出診需要記錄時間、患者信息。
  • 患者
    患者列表信息,可以對患者進(jìn)行分組(以標(biāo)簽形式),可以查找患者,點擊某個患者,可以看到患者的詳細(xì)信息,繼續(xù)點擊可以看到歷史病歷信息。這部分內(nèi)容原則上來自于基層醫(yī)療機(jī)構(gòu)的HIS系統(tǒng),在初期可以只使用本系統(tǒng)數(shù)據(jù)。
  • 消息
    醫(yī)患之間可以通過圖文消息方式進(jìn)行溝通。醫(yī)生還可以通過這個界面發(fā)送患教文章給指定患者。
  • 醫(yī)院
    醫(yī)院的一些管理功能,包括排班信息、患者簽約、家庭病床、通知公告。
  • 我的
    可以進(jìn)行一些個性化設(shè)置,如是否接收患者咨詢等。

建立底部選項卡

底部選項卡每個代表一個頁面,因此我們需要定義5個新頁面。我們在Android Studio中選中工程的lib文件夾,點擊右鍵,創(chuàng)建一個文件夾命名為views,將所有程序中用到的頁面放到此文件中。然后選中該文件夾,點擊右鍵,新建dart文件,分別建立如下5個文件:

  • 日程
import 'package:flutter/material.dart';

class SchedulePage extends StatefulWidget {
  @override
  SchedulePageState createState() => new SchedulePageState();
}

class SchedulePageState extends State<SchedulePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('日程管理')
      ),
      body: new Center(
        child: new Text('醫(yī)生日程管理')
      )
    );
  }
}
  • 患者
import 'package:flutter/material.dart';

class PatientPage extends StatefulWidget {
  @override
  PatientPageState createState() => new PatientPageState();
}

class PatientPageState extends State<PatientPage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
            title: new Text('患者管理')
        ),
        body: new Center(
            child: new Text('患者管理之患者列表')
        )
    );
  }
}
  • 消息
import 'package:flutter/material.dart';

class ImPage extends StatefulWidget {
  @override
  ImPageState createState() => new ImPageState();
}

class ImPageState extends State<ImPage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
            title: new Text('消息管理')
        ),
        body: new Center(
            child: new Text('消息管理之消息列表')
        )
    );
  }
}
  • 醫(yī)院
import 'package:flutter/material.dart';

class HospitalPage extends StatefulWidget {
  @override
  HospitalPageState createState() => new HospitalPageState();
}

class HospitalPageState extends State<HospitalPage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
            title: new Text('醫(yī)院行政管理')
        ),
        body: new Center(
            child: new Text('醫(yī)院行政管理頁面')
        )
    );
  }
}
  • 我的
import 'package:flutter/material.dart';

class MinePage extends StatefulWidget {
  @override
  MinePageState createState() => new MinePageState();
}

class MinePageState extends State<MinePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
            title: new Text('我的')
        ),
        body: new Center(
            child: new Text('我的管理')
        )
    );
  }
}

我們還需在主界面中加入我們定義的TabBar,打開main.dart文件,將內(nèi)容修改為如下所示:

import 'package:flutter/material.dart';
import './views/SchedulePage.dart';
import './views/PatientPage.dart';
import './views/ImPage.dart';
import './views/HospitalPage.dart';
import './views/MinePage.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or press Run > Flutter Hot Reload in IntelliJ). Notice that the
        // counter didn't reset back to zero; the application is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: '隨診醫(yī)生'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  int _counter = 0;

  TabController tabController;

  @override
  void initState() {
    tabController = new TabController(vsync: this, length: 5);
  }

  @override
  void dispose() {
    tabController.dispose();
    super.dispose();
  }

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return new Scaffold(
      body: new TabBarView(
        controller: tabController,
        children: <Widget>[
          new SchedulePage(),
          new PatientPage(),
          new ImPage(),
          new HospitalPage(),
          new MinePage()
        ],
      ),
      bottomNavigationBar: new Material(
        color: Colors.lightBlue,
        child: new TabBar(
          controller: tabController,
          tabs: <Tab>[
            new Tab(text: '日程', icon: new Icon(Icons.home)),
            new Tab(text: '患者', icon: new Icon(Icons.account_box)),
            new Tab(text: '消息', icon: new Icon(Icons.chat_bubble_outline)),
            new Tab(text: '醫(yī)院', icon: new Icon(Icons.apps)),
            new Tab(text: '我的', icon: new Icon(Icons.build)),
          ]
        )
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

這部分代碼應(yīng)該還是很好理解的,而且Flutter一個非常好的特性就是他提供了很多預(yù)置的內(nèi)容,比如TabBar的圖標(biāo),就不用我們費時費力去找,直接使用即可。
在Android Studio中運行該程序,可以得到如下所示的界面:


首頁面效果預(yù)覽

寫到這里不禁感慨,Google的Flutter真的十分強(qiáng)大,從完全不知道Flutter為何物,到做出這個界面,除去系統(tǒng)安裝之外,僅僅花了不到一個小時的時間,還包括百度一些奇奇怪怪的東西,太強(qiáng)大了。而且這個程序不僅可以在Android上運行,還可以在IOS系統(tǒng)上運行,性能上優(yōu)于流行的ReactNative,忍不住要為Google Flutter點贊了。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容