-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I implement jinja for flutter with below template? #12
Comments
"{% if field_manager_phone and field_manager_name %}, or you can directly call your {field_manager_name} at {field_manager_phone} {% endif %}. We look forward" |
Something like that? import 'package:flutter/material.dart';
import 'package:jinja/jinja.dart';
import 'package:provider/provider.dart';
const source1 =
'... {% if phone and name %}, or you can directly call your {{ name }} at {{ phone }} {% endif %}. We look forward ...';
void main() {
runApp(
Provider<Environment>(
create: (context) {
var loader = MapLoader({'source1': source1});
return Environment(loader: loader);
},
child: const App(),
),
);
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Flutter Demo',
home: HomePage(title: 'Flutter Demo Home Page'),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key, required this.title});
final String title;
@override
State<HomePage> createState() {
return HomePageState();
}
}
class HomePageState extends State<HomePage> {
int counter = 0;
String phone = '';
String name = '';
late Template template;
@override
void initState() {
super.initState();
template = context.read<Environment>().getTemplate('source1');
}
void incrementCounter() {
setState(() {
counter += 1;
if (counter % 2 == 0) {
phone = '<phone>';
} else {
phone = '';
}
if (counter % 3 == 0) {
name = '<name>';
} else {
name = '';
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('You have pushed the button this many times:'),
Text('$counter', style: Theme.of(context).textTheme.headline4),
const Text('Template render:'),
Text(template.renderMap({'phone': phone, 'name': name})),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
} |
No description provided.
The text was updated successfully, but these errors were encountered: