flutter_bangla_math 0.2.0
flutter_bangla_math: ^0.2.0 copied to clipboard
Render mixed Bangla text and LaTeX math in Flutter without breaking Bengali glyph shaping.
flutter_bangla_math #
flutter_bangla_math renders mixed Bangla text and LaTeX math in Flutter
without breaking Bengali glyph shaping. It uses flutter_math_fork for TeX
rendering and bundles Noto Sans Bengali so it works on Android, iOS, web,
Linux, macOS, and Windows without depending on runtime font fetching.
Features #
- Inline math with
$...$ - Block math with
$$...$$ - Escaped dollar handling with
\$ - Bangla text rendered with Noto Sans Bengali by default
- Inline math baseline alignment tuned for mixed Bangla and math on the same line
- Offline-safe bundled Noto Sans Bengali font loading
- Simple LRU cache for repeated math fragments
Installation #
dependencies:
flutter_bangla_math: ^0.2.0
The current package version targets Flutter >=3.35.0 and Dart ^3.9.0
because it uses the current google_fonts and flutter_lints releases that
fit cleanly on current Flutter stable.
Usage #
import 'package:flutter/material.dart';
import 'package:flutter_bangla_math/flutter_bangla_math.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await ensureBanglaMathFontsLoaded(disableRuntimeFetching: true);
runApp(const DemoApp());
}
class DemoApp extends StatelessWidget {
const DemoApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Padding(
padding: EdgeInsets.all(24),
child: BanglaMathText(
data: 'যদি $a^2+b^2=c^2$ হয়, তবে এটি সমকোণী ত্রিভুজ।',
),
),
),
);
}
}
Block Math #
const BanglaMathText(
data: 'সমীকরণটি হল:\n\n$$\\int_0^1 x^2\\,dx=\\frac{1}{3}$$',
);
Custom Text Style #
const BanglaMathText(
data: 'ধরি $f(x)=x^2+1$',
style: TextStyle(fontSize: 20, color: Colors.black87),
);
API #
BanglaMathText({
required String data,
TextStyle? style,
MathConfig? mathConfig,
String? fontFamily,
Locale locale = const Locale('bn'),
TextAlign textAlign = TextAlign.start,
bool softWrap = true,
TextScaler? textScaler,
MathWidgetCache? cache,
})
MathConfig controls inline scaling, block spacing, parser settings, and error
fallback styling.
Notes #
- Unmatched
$or$$delimiters fall back to plain text instead of crashing. - The package bundles only Noto Sans Bengali to keep size lower.
- The Noto Sans Bengali OFL text remains in the repository for reference, but it is not bundled into runtime Flutter assets.
- On web,
flutter_math_forkworks for normal cases. If your app needs a KaTeX-based HTML fallback for highly specialized equations, keep that as an app-level escape hatch rather than part of this package API.
Development #
flutter pub get
flutter analyze
flutter test