Flutter

顶部AppBar的功能实现及其actions属性的封装

2018-11-22  本文已影响0人  王保全_1098
import 'package:flutter/material.dart';
import 'package:zybdapp/common_views/appbar_actions.dart';

class UserCenterScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '中油北斗',
      home: Scaffold(
        appBar: MyAppBarActions().getAppBar("我的"),
        body: _UserCenterScreen(),
      ),
    );
  }
}

class _UserCenterScreen extends StatefulWidget {
  @override
  _UserCenterScreenState createState() => _UserCenterScreenState();
}

class _UserCenterScreenState extends State<_UserCenterScreen> {
  @override
  void initState() {
    super.initState();
    print("我的");
  }

  @override
  Widget build(BuildContext context) {
    return Text("");
  }
}

/**
 * 顶部AppBar的actions属性的封装
 */

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class MyAppBarActions {
  AppBar getAppBar(String title) {
    return AppBar(
      title: Text(title, style: TextStyle(color: Colors.white)),
      backgroundColor: Color(0xffF65C0A),
      centerTitle: false,
      actions: <Widget>[
        Row(
          children: <Widget>[
            Text("4006820016"),
            IconButton(
                icon:
                    Image(image: AssetImage("assets/images/appbar_phone.png")),
                onPressed: () {
                  _dial();
                }),
          ],
        ),
        IconButton(
            icon: Image(image: AssetImage("assets/images/appbar_suggest.png")),
            onPressed: () {
              // do nothing
            }),
        IconButton(
            icon: Image(image: AssetImage("assets/images/appbar_message.png")),
            onPressed: () {
              // do nothing
            }),
      ],
    );
  }

  // 拨打电话
  _dial() async {
    const url = 'tel:4006820016';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }
}
上一篇 下一篇

猜你喜欢

热点阅读