首页 > 其他分享 >Flutter之我的界面搭建

Flutter之我的界面搭建

时间:2023-11-16 21:02:01浏览次数:20  
标签:const color onTap children Colors child 界面 Flutter 搭建

先看效果图:

此篇文章用来记录学习Flutter用,如果对你有帮助的话,就点个赞吧,hiahia~


mine.png


界面代码如下:


import 'package:ecology/utils/toast.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';

class MinePage extends StatelessWidget {
  MinePage({Key? key}) : super(key: key);

  static String routeName = '/mine';

  final logic = Get.put(MineLogic());
  final state = Get.find<MineLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Color(0xffEEEEEE),
      child: Column(
        children: [
          _buildTitle(context),
          Expanded(
              child: ListView(
            padding: EdgeInsets.only(top: 0),
            children: <Widget>[
              _buildMoreActions(),
              _buildBottom(),
            ],
          ))
        ],
      ),
    );
  }

  //顶部标题
  Widget _buildTitle(BuildContext context) {
    return SizedBox(
      height: 150,
      child: Stack(
        children: [
          Container(
            height: 120,
            padding:
                const EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10),
            //color: Colors.white,
            decoration: const BoxDecoration(
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(10.0),
                bottomRight: Radius.circular(10.0),
              ),
              color: Colors.purple,
            ),
            child:  Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                InkWell(
                  child: const CircleAvatar(
                    radius: 30.0,
                    backgroundImage: AssetImage('assets/images/head.png'),
                  ),
                  onTap: (){XToast.show('小可爱');},
                ),

                const Padding(
                  padding: EdgeInsets.symmetric(horizontal: 10),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text(
                        '皮皮猪',
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 16.0,
                            color: Colors.white),
                      ),
                      SizedBox(
                        height: 2,
                      ),
                      Text(
                        '温暖小窝的主人',
                        style: TextStyle(
                          fontSize: 10.0,
                          color: Colors.white,
                        ),
                      ),
                      SizedBox(
                        height: 2,
                      ),
                      Text(
                        '120关注 | 100粉丝',
                        style: TextStyle(
                          fontSize: 10.0,
                          color: Colors.white,
                        ),
                      ),
                    ],
                  ),
                ),
                // 右上方的两个图标
                const Spacer(), // 添加一个间距以将图标推到右上方
                InkWell(
                  child: const Icon(
                    Icons.adf_scanner_outlined,
                    color: Colors.white,
                  ),
                  onTap: (){XToast.show('扫描');},
                ),
                const SizedBox(width: 10.0), // 用于创建图标之间的间距
                InkWell(
                  child: const Icon(
                    Icons.settings,
                    color: Colors.white,
                  ),
                  onTap: (){},
                ),
              ],
            ),
          ),
          Positioned(
              bottom: 0.0,
              left: 0.0,
              right: 0.0,
              child: Container(
                margin: const EdgeInsets.symmetric(horizontal: 5),
                padding: const EdgeInsets.symmetric(horizontal: 10),
                height: 60,
                width: MediaQuery.of(context).size.width,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5),
                  color: Colors.white,
                ),
                child:  Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      child: InkWell(
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: <Widget>[
                            Icon(Icons.mode_edit_outlined),
                            Text(
                              '我的创作',
                              style: TextStyle(fontSize: 10),
                            ),
                          ],
                        ),
                        onTap: (){XToast.show('我的创作');},
                      ),
                    ),
                    const VerticalDivider(
                      indent: 15,
                      endIndent: 15,
                      color: Color(0xFFEEEEEE),
                    ),
                    Expanded(
                      child: InkWell(
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: <Widget>[
                            Icon(Icons.notifications_none),
                            Text(
                              '我的消息',
                              style: TextStyle(fontSize: 10),
                            ),
                          ],
                        ),
                        onTap: (){XToast.show('我的消息');},
                      ),
                    ),
                    const VerticalDivider(
                      indent: 15,
                      endIndent: 15,
                      color: Color(0xFFEEEEEE),
                    ),
                    Expanded(
                      child: InkWell(
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: <Widget>[
                            Icon(Icons.bookmark_add_outlined),
                            Text(
                              '我的收藏',
                              style: TextStyle(fontSize: 10),
                            ),
                          ],
                        ),
                        onTap: (){XToast.show('我的收藏');},
                      ),
                    ),
                    const VerticalDivider(
                      indent: 15,
                      endIndent: 15,
                      color: Color(0xFFEEEEEE),
                    ),
                    Expanded(
                      child: InkWell(
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: <Widget>[
                            Icon(Icons.receipt),
                            Text(
                              '浏览记录',
                              style: TextStyle(fontSize: 10),
                            ),
                          ],
                        ),
                        onTap: (){XToast.show('浏览记录');},
                      ),
                    ),
                    const VerticalDivider(
                      indent: 15,
                      endIndent: 15,
                      color: Color(0xFFEEEEEE),
                    ),
                    Expanded(
                      child: InkWell(
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: <Widget>[
                            Icon(Icons.wallet),
                            Text(
                              '我的钱包',
                              style: TextStyle(fontSize: 10),
                            ),
                          ],
                        ),
                        onTap: (){XToast.show('我的钱包');},
                      ),
                    ),
                  ],
                ),
              ))
        ],
      ),
    );
  }

  Widget _buildMoreActions() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 5, vertical: 5),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              Expanded(
                child: InkWell(
                  child: _gradientContainer(
                    icon: Icons.location_city,
                    text1: '企业模式',
                    text2: '企业助力业务拓展',
                  ),
                  onTap: (){XToast.show('企业模式');},
                ),
              ),
              const SizedBox(
                width: 5,
              ),
              Expanded(
                child: InkWell(
                  child: _gradientContainer(
                    icon: Icons.star,
                    text1: '积分商城',
                    text2: '海量商品积分兑换',
                  ),
                  onTap: (){XToast.show('积分商城');},
                ),
              ),
            ],
          ),
          const SizedBox(
            height: 5,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              Expanded(
                child: InkWell(
                  child: _gradientContainer(
                    icon: Icons.next_plan,
                    text1: '内容计划',
                    text2: '打造更多优质内容',
                  ),
                  onTap: (){XToast.show('内容计划');},
                ),
              ),
              SizedBox(
                width: 5,
              ),
              Expanded(
                child: InkWell(
                  child: _gradientContainer(
                    icon: Icons.card_giftcard,
                    text1: '邀请有礼',
                    text2: '邀请好友得大礼',
                  ),
                  onTap: (){XToast.show('邀请有礼');},
                ),
              ),
            ],
          )
        ],
      ),
    );
  }

  //渐变Container
  Widget _gradientContainer(
      {required IconData icon, required String text1, required String text2}) {
    return Container(
      height: 80,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(5.0),
        gradient: const LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [
            Color(0xFFf9ffff),
            Colors.white
          ], // Adjust the gradient colors as needed
        ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          Icon(
            icon,
            color: Colors.black,
            size: 32.0,
          ),
          Padding(
            padding: const EdgeInsets.all(5),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  text1,
                  style: const TextStyle(
                    color: Colors.black,
                    fontSize: 14.0,
                  ),
                ),
                SizedBox(height: 4,),
                Text(
                  text2,
                  style: const TextStyle(
                    color: Colors.grey,
                    fontSize: 10.0,
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

  Widget _buildBottom() {
    return Container(
      margin: const EdgeInsets.only(left: 5,right: 5),
      padding: const EdgeInsets.all(5),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10),
        color: Colors.white,
      ),
      child: Column(
        children: [
          Material(
            color: Colors.white,
            child: InkWell(
              child: const Padding(
                padding: EdgeInsets.fromLTRB(5.0, 10.0, 5.0, 10.0),
                child: Row(
                  children: [
                    Expanded(
                        child: Text(
                      '安全设置',
                      style: TextStyle(fontSize: 13),
                    )),
                    Icon(Icons.chevron_right),
                  ],
                ),
              ),
              onTap: (){},
            ),
          ),
          const Divider(height: 0.1,indent: 5,endIndent: 10,color: Color(0xFFEEEEEE),),
          Material(
            color: Colors.white,
            child: InkWell(
              child: const Padding(
                padding: EdgeInsets.fromLTRB(5.0, 10.0, 5.0, 10.0),
                child: Row(
                  children: [
                    Expanded(
                        child: Text(
                      '系统设置',
                      style: TextStyle(fontSize: 13),
                    )),
                    Icon(Icons.chevron_right),
                  ],
                ),
              ),
              onTap: (){},
            ),
          ),
          const Divider(height: 0.1,indent: 5,endIndent: 10,color: Color(0xFFEEEEEE),),
          Material(
            color: Colors.white,
            child: InkWell(
              child: const Padding(
                padding: EdgeInsets.fromLTRB(5.0, 10.0, 5.0, 10.0),
                child: Row(
                  children: [
                    Expanded(
                        child: Text(
                      '联系我们',
                      style: TextStyle(fontSize: 13),
                    )),
                    Icon(Icons.chevron_right),
                  ],
                ),
              ),
              onTap: (){},
            ),
          ),
          const Divider(height: 0.1,indent: 5,endIndent: 10,color: Color(0xFFEEEEEE),),
          Material(
            color: Colors.white,
            child: InkWell(
              child: const Padding(
                padding: EdgeInsets.fromLTRB(5.0, 10.0, 5.0, 10.0),
                child: Row(
                  children: [
                    Expanded(
                        child: Text(
                      '常见问题',
                      style: TextStyle(fontSize: 13),
                    )),
                    Icon(Icons.chevron_right),
                  ],
                ),
              ),
              onTap: (){},
            ),
          )
        ],
      ),
    );
  }
}

标签:const,color,onTap,children,Colors,child,界面,Flutter,搭建
From: https://blog.51cto.com/xaye/8432567

相关文章

  • redis官方集群搭建
    1.下载releases7.2.0(最好下载源码在服务器编译):https://packages.redis.io/redis-stack/redis-stack-server-7.2.0-v6.rhel7.x86_64.tar.gz?_gl=1*jh1xlt*_ga*MTA3MjY3MzAyMi4xNjgwNzQ0NTE2*_ga_8BKGRQKRPV*MTcwMDEzNzc3NS41LjEuMTcwMDEzNzgwNi4yOS4wLjA.*_gcl_au*MTI3NTM4NTEwNi4xN......
  • 深度学习笔记:搭建基于Python的tensorflow运行环境1
    使用python3命令创建tensorflow虚拟运行环境首先,在系统下创建python虚拟环境目录Venvs,本文我们设置的虚拟环境目录如下:C:\Users\wuchh\venvs,接下来打开cmd命令窗口进入创建的目录(C:\Users\wuchh\venvs)。在命令行窗口中,执行创建虚拟环境的python3命令,我们将创建一个名为......
  • DNS服务器搭建与配置
    来源:https://cshihong.github.io/2018/10/15/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%90%AD%E5%BB%BA%E4%B8%8E%E9%85%8D%E7%BD%AE/DNS服务介绍DNS服务简介:DNS(DomainNameSystem–域名系统),是因特网的一项服务。它作为将域名和IP地址相互映射的一个分布式数据库,能够使人更方便......
  • 微服务 搭建 Eureka 注册中心
     代码示例:启动类: @SpringBootApplication@EnableEurekaServer//自动装配的开关publicclassEurekaApplication{publicstaticvoidmain(String[]args){SpringApplication.run(EurekaApplication.class,args);}}application.yml配置文件: serv......
  • Windows10+VisualStudio2022+CMake+Qt开发环境搭建
    一、概述之前一直使用QtCreator当做QT的开发工具,也没觉得有啥问题。最近使用了VisualStudio+Cmake写了一些SDL2和FFmpeg的东西感觉这个VisualStudio这个工具挺好用的。就萌生了要使用VisualStudio开发Qt的想法。有了这个想法之后就想着需要搭建一个开发环境。百度搜索了......
  • 【操作系统MIT 6.1810(2022版)笔记】Lab实验:环境搭建——以Ubuntu20.04为例
    感觉环境搭建没有别人说的那么难。我是双系统用户(Win+Ubuntu20.04),所以直接在Ubuntu上搭建了。听别人说不要用Ubuntu18.04搭建,不知道为什么参考链接:官网环境搭建教程环境搭建打开终端,输入以下命令并回车运行sudoapt-getinstallgitbuild-essentialgdb-multiarchqemu-s......
  • GUI界面实现小学生口算题卡功能(一)| 简要了解GUI
    上课没认真听,下课不好好写。关于GUI,首先了解了一下什么是GUI:GUI(GraphicalUserInterface),图形用户界面。采用图形方式显示的计算机操作用户接口。与早期计算机使用的命令行界面相比,图形界面对于用户来说在视觉上更容易接受。GUI和CLI(命令行界面)最大的不同是,GUI引入鼠标作为输......
  • 1-1 计算机基础和py环境搭建
    ​1.计算机基础1.1基本概念计算机组成:计算机是由多个硬件组合而成的东西,常见的硬件有:CPU、硬盘、内存、网卡、显示器、机箱、电源等等但单纯地组合并不能协作操作系统:用于协调计算机各个硬件,让硬件之间进行协同工作,以完成某个目标常见的操作系统:windows-xp\win7\win1......
  • 搭建Samba服务器笔记全套
    Top目录安装端口与服务管理其他常用命令配置全局配置共享库配置用户名密码认证库配置Samba登录用户配置防火墙配置设定安全的上下文关系本地系统设置访问读写权限Pdbedit用法Smbpasswd用法其他Windows下相关转发查看网络连接--可删除缓存,用于切换登录用户Windows设置Smb......
  • Windows下搭建Linux开发环境(vagrant)
     [下载]vagrant软件:https://www.virtualbox.org/wiki/Downloads centos镜像: http://isoredirect.centos.org/centos/7/isos/x86_64/ [安装]1.新建虚拟机新建:- 指定主机名称-类型:Linux-版本:RedHat(64-bit) 点击下一步,可以根据实际需要调整CPU和内存,后面的直接点击下一......