了解如何使用 Pocket Code 的拖放可视化设计器,为 React、Flutter 和原生应用构建用户界面。
可视化设计器是 Pocket Code 中最强大的功能之一。它让你能够以可视化的方式创建用户界面,并自动生成简洁、可用于生产环境的代码。
在手机屏幕上设计 UI 颇具挑战。在小屏幕上手动编写布局代码既缓慢又容易出错。可视化设计器通过直观的拖放界面解决了这个问题。
设计器分为以下几部分:
| 组件 | 说明 |
|---|---|
| Container | 弹性容器 |
| Row | 水平排列元素 |
| Column | 垂直排列元素 |
| Grid | CSS Grid 布局 |
| Stack | 重叠元素 |
| Scroll | 可滚动区域 |
| 组件 | 说明 |
|---|---|
| Button | 带多种样式的按钮 |
| TextInput | 文本输入框 |
| Toggle | 开/关切换开关 |
| Slider | 数值选择器 |
| Dropdown | 下拉菜单 |
| Checkbox | 复选框 |
| RadioGroup | 单选选项 |
| 组件 | 说明 |
|---|---|
| Text | 带样式的文本 |
| Image | 图片/图标 |
| Card | 信息卡片 |
| List | 动态列表 |
| Badge | 通知徽标 |
| Avatar | 头像图片 |
| Divider | 视觉分隔线 |
| 组件 | 说明 |
|---|---|
| NavBar | 顶部导航栏 |
| TabBar | 标签页导航 |
| Drawer | 侧边菜单 |
| BottomNav | 底部导航 |
| Breadcrumb | 层级导航 |
让我们一步步创建一个完整的登录界面:
将一个 Column 拖到画布上并配置:
在该列内部,拖入一个 Image:
添加两个 TextInput 组件:
邮箱:
密码:
拖入一个 Button:
添加 Text 组件用于:
设计器会自动生成简洁的代码:
// React output
export function LoginScreen() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
return (
<div className="flex flex-col items-center justify-center min-h-screen bg-neutral-950 p-6">
<img src="/logo.png" alt="Logo" className="w-30 h-30 rounded-full mb-8" />
<input
type="email"
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="w-full p-3 mb-4 bg-neutral-900 rounded-xl
border border-neutral-800 text-white"
/>
<input
type="password"
placeholder="Password"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="w-full p-3 mb-6 bg-neutral-900 rounded-xl
border border-neutral-800 text-white"
/>
<button
className="w-full p-3 bg-blue-600 rounded-xl
text-white font-semibold hover:bg-blue-700"
>
Log In
</button>
<p className="mt-4 text-neutral-500 text-sm">
Don't have an account? <span className="text-blue-400">Sign up</span>
</p>
</div>
);
}
// Flutter output
class LoginScreen extends StatefulWidget {
@override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final emailController = TextEditingController();
final passwordController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF0A0A0A),
body: Center(
child: Padding(
padding: EdgeInsets.all(24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
radius: 60,
backgroundImage: AssetImage('assets/logo.png'),
),
SizedBox(height: 32),
TextField(
controller: emailController,
decoration: InputDecoration(
hintText: 'Email',
prefixIcon: Icon(Icons.mail),
),
),
SizedBox(height: 16),
TextField(
controller: passwordController,
obscureText: true,
decoration: InputDecoration(
hintText: 'Password',
prefixIcon: Icon(Icons.lock),
),
),
SizedBox(height: 24),
ElevatedButton(
onPressed: () {},
child: Text('Log In'),
style: ElevatedButton.styleFrom(
minimumSize: Size(double.infinity, 48),
),
),
],
),
),
),
);
}
}
设计器会自动处理响应式:
%、rem 和 flex,而非固定像素将组件连接到数据:
将你的设计保存为模板:
设计器专为触摸交互而设计:
| 框架 | 状态 | 代码质量 |
|---|---|---|
| React/JSX | ✅ 稳定 | 出色 |
| Flutter | ✅ 稳定 | 出色 |
| Android XML | ✅ 稳定 | 非常好 |
| SwiftUI | 🔄 测试版 | 良好 |
| Vue | 📋 计划中 | — |
可视化设计器使 Pocket Code 成为唯一一款可以在同一台设备上既能设计又能编程的移动 IDE。今天就来试试,加速你的开发吧!