flutter 写个简单的界面

起因, 目的:

来源: 客户需求。 着急要,我随便写的,应付一下。

过程:

略,直接看代码,看注释。

代码 1 xxx
java 复制代码
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

// #
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',

      // 隐藏调试模式横幅
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),

      home: TicTacToeHomePage(), // title: 'Flutter Demo Home Page'
    );
  }
}

// 这部分就是一个占位的。  是个初步版本。
// TicTacToeHomePage
// class TicTacToeHomePage extends StatelessWidget {
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(
//         title: Text('Tic Tac Toe'),
//       ),
//       body: Center(
//         child: Text('hey!!!'),
//       ),
//     );
//   }
// }

class TicTacToeHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Row(
          children: <Widget>[
            Image(
              image: AssetImage('assets/images/face.jpg'), // 替换为你的图片路径
              width: 30.0, // Image style
            ),

            SizedBox(width: 10.0), // 间距

            Text('123456 someone@who',
                style: TextStyle(
                    fontWeight: FontWeight.bold, fontSize: 20.0)), // Text style
          ],
        ),
        backgroundColor: Colors.blue, // AppBar style
      ),

      // body: Center(
      //   child: Text('hey!!!'),
      // ),

      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('Welcome to the game Tic Tac Toe',
                style: TextStyle(
                    fontSize: 24.0,
                    color: Colors.orange,
                    fontWeight: FontWeight.bold)),
            // Welcome message with styles
            SizedBox(height: 20.0),
            // 间距
            Image(
              image: AssetImage('assets/images/game_img.jpg'), // 替换为你的图片路径
              width: 300.0, // Image style
            ),
            SizedBox(height: 20.0),
            // 间距
            ElevatedButton(
              style: ElevatedButton.styleFrom(
                backgroundColor: Colors.red, // 按钮背景颜色
                foregroundColor: Colors.white, // 按钮前景色
                padding: EdgeInsets.symmetric(
                    vertical: 10.0, horizontal: 20.0), // 按钮内边距
              ),
              child: Text('Start Game', style: TextStyle(fontSize: 18.0)),
              // Button text style
              onPressed: () {
                print('Key pressed!');
              },
            ),
          ],
        ),
      ),
    );
  }
}

效果图

结论 + todo

  • 最近写的这个几个 flutter:
  • 前面2篇,是用 vscode 写的
  • 这次是用的是 andriod studio,环境配置差不多用了1个小时。
  • andriod studio 很久不用,各种更新。 其实,andriod studio 也挺好的。

老哥留步,支持一下。

相关推荐
葵野寺1 小时前
【RelayMQ】基于 Java 实现轻量级消息队列(七)
java·开发语言·网络·rabbitmq·java-rabbitmq
zyx没烦恼2 小时前
Qt 基础编程核心知识点全解析:含 Hello World 实现、对象树、坐标系及开发工具使用
开发语言·qt
木心爱编程2 小时前
C++链表实战:STL与手动实现详解
开发语言·c++·链表
mkhase2 小时前
9.11-QT-QT的基本使用
开发语言·qt
Kyln.Wu2 小时前
【python实用小脚本-211】[硬件互联] 桌面壁纸×Python梦幻联动|用10行代码实现“开机盲盒”自动化改造实录(建议收藏)
开发语言·python·自动化
gnip2 小时前
链式调用和延迟执行
前端·javascript
SoaringHeart3 小时前
Flutter组件封装:页面点击事件拦截
前端·flutter
杨天天.3 小时前
小程序原生实现音频播放器,下一首上一首切换,拖动进度条等功能
前端·javascript·小程序·音视频
稻草人想看远方3 小时前
GC垃圾回收
java·开发语言·jvm
Dragon Wu3 小时前
React state在setInterval里未获取最新值的问题
前端·javascript·react.js·前端框架