Criação do app
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
// 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:english_words/english_words.dart';
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'W.A Link Generator',
|
||||
theme: ThemeData(primaryColor: Colors.purpleAccent),
|
||||
home: RandomWords(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RandomWords extends StatefulWidget {
|
||||
const RandomWords({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_RandomWordsState createState() => _RandomWordsState();
|
||||
}
|
||||
|
||||
class _RandomWordsState extends State<RandomWords> {
|
||||
final _suggestions = <WordPair>[];
|
||||
//final _biggerFont = const TextStyle(fontSize: 12.0);
|
||||
|
||||
final _saved = <WordPair>{};
|
||||
|
||||
void _pushSaved() {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
final tiles = _saved.map(
|
||||
(WordPair pair) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
pair.asPascalCase,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
final divided = ListTile.divideTiles(
|
||||
context: context,
|
||||
tiles: tiles,
|
||||
).toList();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Saved Suggestions'),
|
||||
),
|
||||
body: ListView(children: divided),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRow(WordPair pair) {
|
||||
final alreadySaved = _saved.contains(pair);
|
||||
|
||||
return ListTile(
|
||||
title: Text(
|
||||
pair.asPascalCase,
|
||||
),
|
||||
trailing: Icon(
|
||||
alreadySaved ? Icons.favorite : Icons.favorite_border,
|
||||
color: alreadySaved ? Colors.red : null,
|
||||
),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
if (alreadySaved) {
|
||||
_saved.remove(pair);
|
||||
} else {
|
||||
_saved.add(pair);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSuggestions() {
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
itemBuilder: /*1*/ (context, i) {
|
||||
if (i.isOdd)
|
||||
return const Divider(
|
||||
thickness: 2.0,
|
||||
); /*2*/
|
||||
|
||||
final index = i ~/ 2; /*3*/
|
||||
if (index >= _suggestions.length) {
|
||||
_suggestions.addAll(generateWordPairs().take(50)); /*4*/
|
||||
}
|
||||
return _buildRow(_suggestions[index]);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('W.A Link Generator'),
|
||||
actions: [
|
||||
IconButton(icon: Icon(Icons.favorite), onPressed: _pushSaved),
|
||||
],
|
||||
),
|
||||
body: _buildSuggestions(),
|
||||
);
|
||||
}
|
||||
}
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
// 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'))),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user