Skip to content

Instantly share code, notes, and snippets.

@muellercornelius
Created May 27, 2021 15:56
Show Gist options
  • Save muellercornelius/62664fb833ccb3ced79c71c4481fe027 to your computer and use it in GitHub Desktop.
Save muellercornelius/62664fb833ccb3ced79c71c4481fe027 to your computer and use it in GitHub Desktop.
Flutter Clock
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Center(
child: SizedBox(
height: 300,
width: 300,
child: Container(
color: Colors.amber[600],
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 50),
SizeProviderWidget(
onChildSize: (size) {
print(size);
print(
"Da könnte man jetzt ein stateful Widget nehmen und die width der Sized Box der zweiten row updaten");
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
child: Text("18",
style: TextStyle(
fontSize: 90,
height: 0.2,
)),
),
Padding(
padding: EdgeInsets.only(right: 6),
child: Text("hrs",
style: TextStyle(
fontSize: 20,
height: 1,
)),
),
],
),
),
SizedBox(
width: 131,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Text("50",
style: TextStyle(
fontSize: 45,
height: 1,
)),
Text("min",
style: TextStyle(
fontSize: 20,
height: 1,
)),
// 2nd spacer
],
),
),
// 2nd spacer
],
),
),
)),
),
);
}
}
class SizeProviderWidget extends StatefulWidget {
final Widget child;
final Function(Size) onChildSize;
const SizeProviderWidget({Key key, this.onChildSize, this.child})
: super(key: key);
@override
_SizeProviderWidgetState createState() => _SizeProviderWidgetState();
}
class _SizeProviderWidgetState extends State<SizeProviderWidget> {
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
widget.onChildSize(context.size);
});
super.initState();
}
@override
Widget build(BuildContext context) {
return widget.child;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment