pubspec.yaml : add flushbar dependencie | lib : delete HomeLog.dart, add endi.dart (start only if deeplink is clicked), add bloc.dart (manage deeplink fonctionnality) | ios/Runner/info.plist : add endi URIs | android/app/src/main/AndroidManifest.xml : add endi URIs | android/app/src/main/kotlin/fr.astrolabe.astronote_app/MainActivity.kt : update to manage deeplink fonctionnality
This commit is contained in:
48
lib/bloc.dart
Normal file
48
lib/bloc.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
abstract class Bloc {
|
||||
void dispose();
|
||||
}
|
||||
|
||||
class DeepLinkBloc extends Bloc {
|
||||
//Event Channel creation
|
||||
static const stream =
|
||||
const EventChannel('https://demo.endi.coop/login?nextpage=%2F');
|
||||
|
||||
//Method channel creation
|
||||
static const platform = const MethodChannel('https://demo.endi.coop');
|
||||
|
||||
StreamController<String> _stateController = StreamController();
|
||||
|
||||
Stream<String> get state => _stateController.stream;
|
||||
|
||||
Sink<String> get stateSink => _stateController.sink;
|
||||
|
||||
//Adding the listener into contructor
|
||||
DeepLinkBloc() {
|
||||
//Checking application start by deep link
|
||||
startUri().then(_onRedirected);
|
||||
//Checking broadcast stream, if deep link was clicked in opened appication
|
||||
stream.receiveBroadcastStream().listen((d) => _onRedirected(d));
|
||||
}
|
||||
|
||||
_onRedirected(String uri) {
|
||||
// Throw deep link URI into the BloC's stream
|
||||
stateSink.add(uri);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_stateController.close();
|
||||
}
|
||||
|
||||
Future<String> startUri() async {
|
||||
try {
|
||||
return platform.invokeMethod('initialLink');
|
||||
} on PlatformException catch (e) {
|
||||
return "Failed to Invoke: '${e.message}'.";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,57 @@
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'bloc.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:flushbar/flushbar.dart';
|
||||
|
||||
class HomeLog extends StatefulWidget {
|
||||
class EndiLog extends StatefulWidget {
|
||||
@override
|
||||
_HomeLogState createState() => _HomeLogState();
|
||||
_EndiLogState createState() => _EndiLogState();
|
||||
}
|
||||
|
||||
class _HomeLogState extends State<HomeLog> {
|
||||
class _EndiLogState extends State<EndiLog> {
|
||||
TextStyle style = TextStyle(fontFamily: 'Varela Round', fontSize: 20.0);
|
||||
final GlobalKey<ScaffoldState> _globalKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
key: _globalKey,
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
color: Colors.white,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(50),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
SizedBox(height: 40),
|
||||
_logoApp(),
|
||||
_titleApp(),
|
||||
SizedBox(height: 90),
|
||||
_emailField(),
|
||||
SizedBox(height: 30),
|
||||
_passwordField(),
|
||||
SizedBox(height: 50),
|
||||
_logButton(),
|
||||
SizedBox(height: 70),
|
||||
_enDIUrl(),
|
||||
SizedBox(height: 10),
|
||||
_astrolabeUrl()
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
DeepLinkBloc _bloc = Provider.of<DeepLinkBloc>(context);
|
||||
return StreamBuilder<String>(
|
||||
stream: _bloc.state,
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return Container(
|
||||
child: Center(child: Text('No deep link was used ')));
|
||||
} else {
|
||||
return SingleChildScrollView(
|
||||
child: Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
color: Colors.white,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(50),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
// SizedBox(height: 40),
|
||||
_logoApp(),
|
||||
_titleApp(),
|
||||
SizedBox(height: 80),
|
||||
_emailField(),
|
||||
SizedBox(height: 30),
|
||||
_passwordField(),
|
||||
SizedBox(height: 50),
|
||||
_logButton(),
|
||||
SizedBox(height: 70),
|
||||
_enDIUrl(),
|
||||
SizedBox(height: 5),
|
||||
_astrolabeUrl()
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Widget _logoApp() {
|
||||
return SizedBox(
|
||||
height: 100.0,
|
||||
@@ -67,7 +76,7 @@ class _HomeLogState extends State<HomeLog> {
|
||||
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
|
||||
labelText: "E-mail",
|
||||
border:
|
||||
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
|
||||
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -79,7 +88,7 @@ class _HomeLogState extends State<HomeLog> {
|
||||
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
|
||||
labelText: "Mot de passe",
|
||||
border:
|
||||
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
|
||||
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -99,18 +108,22 @@ class _HomeLogState extends State<HomeLog> {
|
||||
));
|
||||
}
|
||||
|
||||
void showErrorFlushbar(BuildContext context) {
|
||||
Flushbar(
|
||||
message: "Impossible d'ouvrir le lien",
|
||||
backgroundColor: Colors.red[300],
|
||||
duration: Duration(seconds: 3),
|
||||
// Show it with a cascading operator
|
||||
)..show(context);
|
||||
}
|
||||
|
||||
void _launchLinkEnDI() async {
|
||||
const url = "https://endi.coop";
|
||||
|
||||
if (await canLaunch(url)) {
|
||||
await launch(url);
|
||||
} else {
|
||||
final snack = SnackBar(
|
||||
content: Text("Impossible de lancer le lien"),
|
||||
duration: Duration(seconds: 4),
|
||||
backgroundColor: Colors.red[300],
|
||||
);
|
||||
_globalKey.currentState.showSnackBar(snack);
|
||||
showErrorFlushbar(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,12 +133,7 @@ class _HomeLogState extends State<HomeLog> {
|
||||
if (await canLaunch(url)) {
|
||||
await launch(url);
|
||||
} else {
|
||||
final snack = SnackBar(
|
||||
content: Text("Impossible de lancer le lien"),
|
||||
duration: Duration(seconds: 4),
|
||||
backgroundColor: Colors.red[300],
|
||||
);
|
||||
_globalKey.currentState.showSnackBar(snack);
|
||||
showErrorFlushbar(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,5 +162,4 @@ class _HomeLogState extends State<HomeLog> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'views/HomeLog.dart';
|
||||
import 'bloc.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'endi.dart';
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
@@ -7,11 +9,14 @@ class MyApp extends StatelessWidget {
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
DeepLinkBloc _bloc = DeepLinkBloc();
|
||||
|
||||
return MaterialApp(
|
||||
home: HomeLog(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: Scaffold(
|
||||
body: Provider<DeepLinkBloc>(
|
||||
create: (context) => _bloc,
|
||||
dispose: (context, bloc) => bloc.dispose(),
|
||||
child: EndiLog())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user