mobile id text format

This commit is contained in:
csf 2022-09-21 17:54:47 +08:00
parent 285d415a5a
commit 725c0689e2
3 changed files with 15 additions and 13 deletions

View File

@ -77,7 +77,7 @@ class _PeerCardState extends State<_PeerCard>
child: ListTile( child: ListTile(
contentPadding: const EdgeInsets.only(left: 12), contentPadding: const EdgeInsets.only(left: 12),
subtitle: Text('${peer.username}@${peer.hostname}'), subtitle: Text('${peer.username}@${peer.hostname}'),
title: Text(peer.id), title: Text(formatID(peer.id)),
leading: Container( leading: Container(
padding: const EdgeInsets.all(6), padding: const EdgeInsets.all(6),
color: str2color('${peer.id}${peer.platform}', 0x7f), color: str2color('${peer.id}${peer.platform}', 0x7f),

View File

@ -60,7 +60,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
children: [ children: [
Row( Row(
children: [ children: [
getSearchBarUI(context), _buildRemoteIDTextField(context),
], ],
).marginOnly(top: 22), ).marginOnly(top: 22),
SizedBox(height: 12), SizedBox(height: 12),
@ -97,9 +97,9 @@ class _ConnectionPageState extends State<ConnectionPage> {
connect(context, id, isFileTransfer: isFileTransfer); connect(context, id, isFileTransfer: isFileTransfer);
} }
/// UI for the search bar. /// UI for the remote ID TextField.
/// Search for a peer and connect to it if the id exists. /// Search for a peer and connect to it if the id exists.
Widget getSearchBarUI(BuildContext context) { Widget _buildRemoteIDTextField(BuildContext context) {
RxBool ftHover = false.obs; RxBool ftHover = false.obs;
RxBool ftPressed = false.obs; RxBool ftPressed = false.obs;
RxBool connHover = false.obs; RxBool connHover = false.obs;

View File

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hbb/common/formatter/id_formatter.dart';
import 'package:flutter_hbb/mobile/pages/file_manager_page.dart'; import 'package:flutter_hbb/mobile/pages/file_manager_page.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -38,7 +39,7 @@ class ConnectionPage extends StatefulWidget implements PageShape {
/// State for the connection page. /// State for the connection page.
class _ConnectionPageState extends State<ConnectionPage> { class _ConnectionPageState extends State<ConnectionPage> {
/// Controller for the id input bar. /// Controller for the id input bar.
final _idController = TextEditingController(); final _idController = IDTextEditingController();
/// Update url. If it's not null, means an update is available. /// Update url. If it's not null, means an update is available.
var _updateUrl = ''; var _updateUrl = '';
@ -49,9 +50,9 @@ class _ConnectionPageState extends State<ConnectionPage> {
if (_idController.text.isEmpty) { if (_idController.text.isEmpty) {
() async { () async {
final lastRemoteId = await bind.mainGetLastRemoteId(); final lastRemoteId = await bind.mainGetLastRemoteId();
if (lastRemoteId != _idController.text) { if (lastRemoteId != _idController.id) {
setState(() { setState(() {
_idController.text = lastRemoteId; _idController.id = lastRemoteId;
}); });
} }
}(); }();
@ -72,8 +73,8 @@ class _ConnectionPageState extends State<ConnectionPage> {
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
getUpdateUI(), _buildUpdateUI(),
getSearchBarUI(), _buildRemoteIDTextField(),
Expanded( Expanded(
child: PeerTabPage( child: PeerTabPage(
tabs: [ tabs: [
@ -95,7 +96,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
/// Callback for the connect button. /// Callback for the connect button.
/// Connects to the selected peer. /// Connects to the selected peer.
void onConnect() { void onConnect() {
var id = _idController.text.trim(); var id = _idController.id;
connect(id); connect(id);
} }
@ -132,7 +133,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
/// UI for software update. /// UI for software update.
/// If [_updateUrl] is not empty, shows a button to update the software. /// If [_updateUrl] is not empty, shows a button to update the software.
Widget getUpdateUI() { Widget _buildUpdateUI() {
return _updateUrl.isEmpty return _updateUrl.isEmpty
? const SizedBox(height: 0) ? const SizedBox(height: 0)
: InkWell( : InkWell(
@ -152,9 +153,9 @@ class _ConnectionPageState extends State<ConnectionPage> {
color: Colors.white, fontWeight: FontWeight.bold)))); color: Colors.white, fontWeight: FontWeight.bold))));
} }
/// UI for the search bar. /// UI for the remote ID TextField.
/// Search for a peer and connect to it if the id exists. /// Search for a peer and connect to it if the id exists.
Widget getSearchBarUI() { Widget _buildRemoteIDTextField() {
final w = SizedBox( final w = SizedBox(
height: 84, height: 84,
child: Padding( child: Padding(
@ -197,6 +198,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
), ),
), ),
controller: _idController, controller: _idController,
inputFormatters: [IDTextInputFormatter()],
), ),
), ),
), ),