Skip to content

Instantly share code, notes, and snippets.

@Fraganya
Forked from HansMuller/appbar_jumbo_title.dart
Created December 12, 2019 02:14
Show Gist options
  • Save Fraganya/0c76975e3cc726435e0915b1d11de27c to your computer and use it in GitHub Desktop.
Save Fraganya/0c76975e3cc726435e0915b1d11de27c to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
class ScaleFactorAppBar extends StatelessWidget {
const ScaleFactorAppBar({
this.textScaleFactor = 1,
this.textDirection = TextDirection.ltr,
this.centerTitle = false,
});
final double textScaleFactor;
final TextDirection textDirection;
final bool centerTitle;
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: textDirection,
child: MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
child: Builder(
builder: (BuildContext context) {
return AppBar(
leading: BackButtonIcon(),
centerTitle: centerTitle,
title: Text('Jumbo'),
actions: <Widget>[ Icon(Icons.menu) ],
);
},
),
),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
const Widget spacer = SizedBox(height: 32);
return Container(
color: Colors.white,
child: SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
spacer,
ScaleFactorAppBar(textScaleFactor: 1),
spacer,
ScaleFactorAppBar(textScaleFactor: 2),
spacer,
ScaleFactorAppBar(textScaleFactor: 3),
spacer,
ScaleFactorAppBar(textScaleFactor: 3.5),
spacer,
ScaleFactorAppBar(textScaleFactor: 4),
],
/*
children: <Widget>[
spacer,
ScaleFactorAppBar(textScaleFactor: 1, textDirection: TextDirection.rtl),
spacer,
ScaleFactorAppBar(textScaleFactor: 2, textDirection: TextDirection.rtl),
spacer,
ScaleFactorAppBar(textScaleFactor: 3, textDirection: TextDirection.rtl),
spacer,
ScaleFactorAppBar(textScaleFactor: 3.5, textDirection: TextDirection.rtl),
spacer,
ScaleFactorAppBar(textScaleFactor: 4, textDirection: TextDirection.rtl),
],
*/
/*
children: <Widget>[
spacer,
ScaleFactorAppBar(textScaleFactor: 1, centerTitle: true),
spacer,
ScaleFactorAppBar(textScaleFactor: 2, centerTitle: true),
spacer,
ScaleFactorAppBar(textScaleFactor: 3, centerTitle: true),
spacer,
ScaleFactorAppBar(textScaleFactor: 3.5, centerTitle: true),
spacer,
ScaleFactorAppBar(textScaleFactor: 4, centerTitle: true),
],
*/
),
),
);
}
}
void main() {
runApp(
MaterialApp(
//theme: ThemeData(platform: TargetPlatform.iOS),
home: HomePage(),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment