Let you create your Flutter application with Lenra backend.
Report Bug
·
Request Feature
Add the dependency to your project:
flutter pub add lenra_clientYou might need some other prerequisites since this lib is still in using flutter_secure_storage. Look at this lib documentation to see what you need.
Add a LenraApplication to your app:
import'package:flutter/material.dart';
import'package:lenra_client/widgets.dart';
voidmain() {
runApp(constMyApp());
}
classMyAppextendsStatelessWidget {
constMyApp({super.key});
// This widget is the root of your application.@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
title:'Flutter Demo',
theme:ThemeData(
colorScheme:ColorScheme.fromSeed(seedColor:Colors.deepPurple),
useMaterial3:true,
),
home:LenraApplication(
// set your own client id for production
clientId:'XXX-XXX-XXX',
child:constMyHomePage(title:'Flutter Demo Home Page'),
),
);
}
}This while automatically start the authentication flow.
You can then add LenraView instances to your widget tree to link the widget to a Lenra view and use it data:
classMyHomePageextendsStatelessWidget {
constMyHomePage({super.key, requiredthis.title});
finalString title;
@overrideWidgetbuild(BuildContext context) {
returnLenraView(
route:"/counter/me",
builder: (
BuildContext context,
Map<String, dynamic> json,
ListenerCaller callListener,
) =>Scaffold(
appBar:AppBar(
backgroundColor:Theme.of(context).colorScheme.inversePrimary,
title:Text(title),
),
body:Center(
child:Column(
mainAxisAlignment:MainAxisAlignment.center,
children:<Widget>[
constText(
'You have pushed the button this many times:',
),
Text(
'${json["value"]}',
style:Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton:FloatingActionButton(
onPressed: () =>callListener(json["onIncrement"]),
tooltip:'Increment',
child:constIcon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
),
loader:constCircularProgressIndicator(),
);
}
}For the web target, you also have to add the following JavaScript to a redirect file (default to redirect.html) to handle OAuth2 redirection (see the example):
window.onload=function(){window.opener.postMessage(window.location.href,`${window.location.protocol}//${window.location.host}`);}Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please open an issue with the tag "enhancement". Don't forget to give the project a star if you liked it! Thanks again!
Distributed under the MIT License. See LICENSE for more information.
Lenra - @lenra_dev - contact@lenra.io
Project Link: https://github.com/lenra-io/client-lib-flutter