Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
org.benoitharrault.random
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
android
org.benoitharrault.random
Commits
d3d14c3d
Commit
d3d14c3d
authored
8 months ago
by
Benoît Harrault
Browse files
Options
Downloads
Patches
Plain Diff
Create styled container widget
parent
c6346730
No related branches found
No related tags found
No related merge requests found
Pipeline
#6013
passed
8 months ago
Stage: build-debug
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/ui/screens/demo_page.dart
+25
-0
25 additions, 0 deletions
lib/ui/screens/demo_page.dart
lib/ui/widgets/styles_widget.dart
+66
-0
66 additions, 0 deletions
lib/ui/widgets/styles_widget.dart
with
91 additions
and
0 deletions
lib/ui/screens/demo_page.dart
+
25
−
0
View file @
d3d14c3d
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:random/ui/widgets/styles_widget.dart'
;
import
'package:unicons/unicons.dart'
;
import
'package:unicons/unicons.dart'
;
import
'package:random/config/theme.dart'
;
import
'package:random/config/theme.dart'
;
...
@@ -29,6 +30,30 @@ class DemoPage extends StatelessWidget {
...
@@ -29,6 +30,30 @@ class DemoPage extends StatelessWidget {
fakeApiCall
(),
fakeApiCall
(),
const
SizedBox
(
height:
20
),
const
SizedBox
(
height:
20
),
const
AppHeader
(
text:
'BOTTOM'
),
const
AppHeader
(
text:
'BOTTOM'
),
const
StyledWidget
(
child:
SizedBox
.
square
(
dimension:
40
,
child:
Center
(
child:
Text
(
'default'
)),
),
),
const
SizedBox
(
height:
8
),
const
StyledWidget
(
borderRadius:
0
,
borderWidth:
12
,
// depth: 8,
lowerColor:
Colors
.
red
,
upperColor:
Colors
.
yellow
,
child:
Center
(
child:
Text
(
'custom 1'
)),
),
const
SizedBox
(
height:
8
),
const
StyledWidget
(
borderRadius:
10
,
borderWidth:
20
,
depth:
20
,
lowerColor:
Colors
.
blueGrey
,
upperColor:
Colors
.
blue
,
child:
Center
(
child:
Text
(
'custom 2'
)),
),
],
],
),
),
);
);
...
...
This diff is collapsed.
Click to expand it.
lib/ui/widgets/styles_widget.dart
0 → 100644
+
66
−
0
View file @
d3d14c3d
import
'package:flutter/material.dart'
;
class
StyledWidget
extends
StatelessWidget
{
const
StyledWidget
({
super
.
key
,
required
this
.
child
,
this
.
borderWidth
=
10
,
this
.
borderRadius
=
4
,
this
.
depth
=
5
,
this
.
lowerColor
,
this
.
upperColor
,
});
final
Widget
child
;
final
double
borderWidth
;
final
double
borderRadius
;
final
int
depth
;
final
Color
?
lowerColor
;
final
Color
?
upperColor
;
Widget
nestedContainers
({
required
Widget
child
,
required
int
containerDepth
,
required
Color
lowerColor
,
required
Color
upperColor
,
})
{
final
double
singleBorderWidth
=
borderWidth
/
depth
;
final
Color
borderColor
=
Color
.
lerp
(
upperColor
,
lowerColor
,
(
containerDepth
/
depth
-
0.5
)
.
abs
()
*
2
)
??
Colors
.
white
;
final
double
radius
=
borderRadius
+
borderRadius
*
(
containerDepth
/
depth
);
return
Container
(
decoration:
BoxDecoration
(
color:
borderColor
,
border:
Border
.
all
(
color:
borderColor
,
width:
singleBorderWidth
,
),
borderRadius:
BorderRadius
.
circular
(
radius
),
),
child:
containerDepth
==
0
?
Padding
(
padding:
const
EdgeInsets
.
all
(
8
),
child:
child
,
)
:
nestedContainers
(
child:
child
,
containerDepth:
containerDepth
-
1
,
lowerColor:
lowerColor
,
upperColor:
upperColor
,
),
);
}
@override
Widget
build
(
BuildContext
context
)
{
return
nestedContainers
(
child:
child
,
containerDepth:
depth
,
lowerColor:
lowerColor
??
Theme
.
of
(
context
)
.
colorScheme
.
onPrimary
,
upperColor:
upperColor
??
Theme
.
of
(
context
)
.
colorScheme
.
onSecondary
,
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment