284 lines
12 KiB
Dart
284 lines
12 KiB
Dart
// Copyright 2018 The Flutter team. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:clipboard/clipboard.dart';
|
|
import 'package:share/share.dart';
|
|
|
|
void main() => runApp(MyApp());
|
|
|
|
class GeraLink {
|
|
final String numero;
|
|
|
|
GeraLink(this.numero);
|
|
|
|
String toString() {
|
|
return 'https://api.whatsapp.com/send?phone=55$numero';
|
|
}
|
|
}
|
|
|
|
final TextEditingController _controladorNumero = TextEditingController();
|
|
final TextEditingController _controladorUrl = TextEditingController();
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_MyAppState createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
final _messengerKey = GlobalKey<ScaffoldMessengerState>();
|
|
|
|
bool _exibir = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
scaffoldMessengerKey: _messengerKey,
|
|
title: 'W.A Link Generator',
|
|
theme: ThemeData(primaryColor: Colors.lightBlue),
|
|
home: Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('W.A Link Generator'),
|
|
),
|
|
body: SingleChildScrollView(
|
|
child: Container(
|
|
child: Center(
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(15.0),
|
|
child: TextField(
|
|
keyboardType: TextInputType.phone,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Número',
|
|
hintText:
|
|
'Digite seu número aqui (com DDD)',
|
|
border: OutlineInputBorder()),
|
|
controller: _controladorNumero,
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
onPressed: () {
|
|
_controladorNumero.text = '';
|
|
_controladorUrl.text = '';
|
|
|
|
// Oculta o campo "URL Gerada" e o botão "Copiar" se estiverem sendo exibidos
|
|
if (_exibir) {
|
|
setState(() {
|
|
_exibir = false;
|
|
});
|
|
}
|
|
},
|
|
icon: Icon(Icons.clear),
|
|
tooltip: 'Limpar',
|
|
)
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(15.0),
|
|
child: ElevatedButton.icon(
|
|
icon: Icon(Icons.replay),
|
|
label: Text('Gerar'),
|
|
onPressed: () {
|
|
if (_controladorNumero.text.isEmpty) {
|
|
_messengerKey.currentState!.showSnackBar(
|
|
SnackBar(
|
|
content: const Text(
|
|
'Preencha o telefone')));
|
|
if (_exibir) {
|
|
setState(() {
|
|
_exibir = false;
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
|
|
final String numero = _controladorNumero.text;
|
|
final GeraLink novoLink = GeraLink(numero);
|
|
|
|
setState(() {
|
|
_controladorUrl.text = novoLink.toString();
|
|
_exibir = true;
|
|
|
|
_messengerKey.currentState!.showSnackBar(
|
|
SnackBar(
|
|
content: const Text('Sucesso!')));
|
|
});
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
//Botão Limpar
|
|
|
|
// Row(
|
|
// children: [
|
|
// Expanded(
|
|
// child: Padding(
|
|
// padding: const EdgeInsets.all(15.0),
|
|
// child: OutlinedButton.icon(
|
|
// onPressed: () {
|
|
// _controladorNumero.text = '';
|
|
// _controladorUrl.text = '';
|
|
|
|
// // Oculta o campo "URL Gerada" e o botão "Copiar" se estiverem sendo exibidos
|
|
// if (_exibir) {
|
|
// setState(() {
|
|
// _exibir = false;
|
|
// });
|
|
// }
|
|
// },
|
|
// icon: Icon(Icons.clear),
|
|
// label: Text('Limpar'))),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
Visibility(
|
|
visible: _exibir,
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(20.0),
|
|
child: TextField(
|
|
decoration: InputDecoration(
|
|
labelText: 'URL gerada',
|
|
border: OutlineInputBorder()),
|
|
controller: _controladorUrl,
|
|
readOnly: true,
|
|
enableInteractiveSelection: true,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Column(
|
|
children: [
|
|
IconButton(
|
|
onPressed: () async {
|
|
final snackBar = SnackBar(
|
|
content:
|
|
const Text('Copiado com sucesso'));
|
|
|
|
// FlutterClipboard.controlC(
|
|
// _controladorUrl.text)
|
|
// .then((value) {
|
|
// if (value) {
|
|
// _messengerKey.currentState!
|
|
// .showSnackBar(snackBar);
|
|
// } else {
|
|
// _messengerKey.currentState!.showSnackBar(
|
|
// SnackBar(
|
|
// content: const Text(
|
|
// 'Erro ao copiar')));
|
|
// }
|
|
// });
|
|
|
|
// .then não depende do retorno para continuar o código
|
|
// await deve ser usado quando você depende do retorno para continuar o código
|
|
|
|
var value = await FlutterClipboard.controlC(
|
|
_controladorUrl.text);
|
|
|
|
if (value) {
|
|
_messengerKey.currentState!
|
|
.showSnackBar(snackBar);
|
|
} else {
|
|
_messengerKey.currentState!.showSnackBar(
|
|
SnackBar(
|
|
content: const Text(
|
|
'Erro ao copiar')));
|
|
}
|
|
},
|
|
icon: Icon(Icons.copy),
|
|
tooltip: 'Copiar',
|
|
)
|
|
],
|
|
),
|
|
Column(
|
|
children: [
|
|
IconButton(
|
|
onPressed: () {
|
|
Share.share(_controladorUrl.text);
|
|
},
|
|
icon: Icon(Icons.share),
|
|
tooltip: 'Compartilhar',
|
|
)
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
// Visibility(
|
|
// visible: _exibir,
|
|
// child: Row(
|
|
// children: [
|
|
// Expanded(
|
|
// child: Padding(
|
|
// padding: const EdgeInsets.all(15.0),
|
|
// child: ElevatedButton.icon(
|
|
// onPressed: () async {
|
|
// final snackBar = SnackBar(
|
|
// content: const Text(
|
|
// 'Copiado com sucesso'));
|
|
|
|
// // FlutterClipboard.controlC(
|
|
// // _controladorUrl.text)
|
|
// // .then((value) {
|
|
// // if (value) {
|
|
// // _messengerKey.currentState!
|
|
// // .showSnackBar(snackBar);
|
|
// // } else {
|
|
// // _messengerKey.currentState!.showSnackBar(
|
|
// // SnackBar(
|
|
// // content: const Text(
|
|
// // 'Erro ao copiar')));
|
|
// // }
|
|
// // });
|
|
|
|
// // .then não depende do retorno para continuar o código
|
|
// // await deve ser usado quando você depende do retorno para continuar o código
|
|
|
|
// var value =
|
|
// await FlutterClipboard.controlC(
|
|
// _controladorUrl.text);
|
|
|
|
// if (value) {
|
|
// _messengerKey.currentState!
|
|
// .showSnackBar(snackBar);
|
|
// } else {
|
|
// _messengerKey.currentState!
|
|
// .showSnackBar(SnackBar(
|
|
// content: const Text(
|
|
// 'Erro ao copiar')));
|
|
// }
|
|
// },
|
|
// icon: Icon(Icons.copy),
|
|
// label: Text('Copiar Link'))),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
)));
|
|
}
|
|
}
|