From d336fad9c6186f87f2eaa782173a7e373685ea9c Mon Sep 17 00:00:00 2001 From: vbastos Date: Mon, 12 Dec 2022 12:13:26 -0300 Subject: [PATCH] usando .env e requisitando flag do unleash --- .env.example | 2 ++ .gitignore | 1 + lib/HomePage.dart | 71 +++++++++++++++++++++++++++++++++++++------ pubspec.lock | 35 +++++++++++++++++++++ pubspec.yaml | 9 ++++-- test/widget_test.dart | 2 +- 6 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..83311cc --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +URL_API= +INSTANCE_ID= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7112847..400dcaa 100644 --- a/.gitignore +++ b/.gitignore @@ -111,3 +111,4 @@ lint/generated/ lint/outputs/ lint/tmp/ # lint/reports/ +.env diff --git a/lib/HomePage.dart b/lib/HomePage.dart index bb5c929..981b28a 100644 --- a/lib/HomePage.dart +++ b/lib/HomePage.dart @@ -1,27 +1,80 @@ import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart' as DotEnv; +import 'package:unleash/unleash.dart'; + class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { + Unleash unl; + @override Widget build(BuildContext context) { + initConfigs(); + String flagText; + return Scaffold( appBar: AppBar( title: Text('Unleash app'), ), - body: Center( - child: Container( - height: 80, - width: 300, - child: Text( - 'Você está logado!!', - style: TextStyle(color: Colors.black, fontSize: 35), - ), + body: SingleChildScrollView( + child: Column( + children: [ + Padding( + padding: const EdgeInsets.all(15), + child: Container( + height: 80, + width: 300, + child: Text( + 'Consulta de flags!!', + style: TextStyle(color: Colors.black, fontSize: 35), + ), + ), + ), + Padding( + padding: const EdgeInsets.all(15), + child: TextField( + decoration: InputDecoration( + border: OutlineInputBorder(), + labelText: 'Flag'), + onChanged: (flag) { + flagText = flag; + }, + ), + ), + Container( + height: 50, + width: 250, + decoration: BoxDecoration( + color: Colors.blue, borderRadius: BorderRadius.circular(20)), + child: FlatButton( + onPressed: () { + print('flag ativa? == ${unl.isEnabled(flagText)}'); + }, + child: Text( + 'Consultar', + style: TextStyle(color: Colors.white, fontSize: 25), + ), + ), + ), + ], ), + ) + ); + } + + Future initConfigs() async { + await DotEnv.load(); + + unl = await Unleash.init( + UnleashSettings( + appName: '', + instanceId: '${DotEnv.env['INSTANCE_ID']}', + unleashApi: Uri.parse('${DotEnv.env['URL_API']}'), ), ); } -} +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 6d31f32..48dbb3f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -76,11 +76,32 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_dotenv: + dependency: "direct main" + description: + name: flutter_dotenv + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.2" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.4" intl: dependency: transitive description: @@ -144,6 +165,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.4+3" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.2" platform: dependency: transitive description: @@ -219,6 +247,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0-nullsafety.3" + unleash: + dependency: "direct main" + description: + name: unleash + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 30ee39b..6a12637 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,4 +1,4 @@ -name: unleash +name: unleash_poc description: A new Flutter project. publish_to: 'none' # Remove this line if you wish to publish to pub.dev @@ -15,6 +15,8 @@ dependencies: path_provider: ^1.6.28 cupertino_icons: ^0.1.3 + flutter_dotenv: ^3.1.0 + unleash: ^0.1.2 dev_dependencies: flutter_test: @@ -22,4 +24,7 @@ dev_dependencies: flutter: - uses-material-design: true \ No newline at end of file + uses-material-design: true + + assets: + - .env \ No newline at end of file diff --git a/test/widget_test.dart b/test/widget_test.dart index c1c23f3..26df395 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:unleash/main.dart'; +import 'package:unleash_poc/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async {