Skip to content

Instantly share code, notes, and snippets.

@HansMuller
Created October 17, 2019 16:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save HansMuller/f782a76d600dd87f78dbd82b84899c8d to your computer and use it in GitHub Desktop.
Save HansMuller/f782a76d600dd87f78dbd82b84899c8d 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